Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webserver): exits with code 0 when SIGTERM is handled #10301

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/server/server.ts
Original file line number Diff line number Diff line change
@@ -47,10 +47,11 @@ process.on('SIGTERM', async (signal) => {
Object.values(activeClients.store).map(async (connectionContext) => {
const disconnectIn = Math.floor(Math.random() * RECONNECT_WINDOW)
await sleep(disconnectIn)
handleDisconnect(connectionContext)
await handleDisconnect(connectionContext)
})
)
console.log(`Server ID: ${process.env.SERVER_ID}. Graceful shutdown complete, exiting.`)
process.exit()
})

const PORT = Number(__PRODUCTION__ ? process.env.PORT : process.env.SOCKET_PORT)
4 changes: 2 additions & 2 deletions packages/server/socketHandlers/handleDisconnect.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ mutation DisconnectSocket($userId: ID!) {
}
}`

const handleDisconnect = (connectionContext: ConnectionContext, options: Options = {}) => {
const handleDisconnect = async (connectionContext: ConnectionContext, options: Options = {}) => {
const {exitCode = 1000, reason} = options
const {authToken, ip, cancelKeepAlive, id: socketId, socket, isDisconnecting} = connectionContext
if (isDisconnecting) return
@@ -28,7 +28,7 @@ const handleDisconnect = (connectionContext: ConnectionContext, options: Options
relayUnsubscribeAll(connectionContext)
if (authToken.rol !== 'impersonate') {
const userId = getUserId(authToken)
publishInternalGQL({authToken, ip, query: disconnectQuery, socketId, variables: {userId}})
await publishInternalGQL({authToken, ip, query: disconnectQuery, socketId, variables: {userId}})
}
activeClients.delete(connectionContext.id)
closeTransport(socket, exitCode, reason)