Skip to content

Conversation

mafredri
Copy link
Member

To prevent additional signals from aborting program execution, signal
handling was moved to the beginning of the main function, this ensures
that signals stays registered for the entire shutdown procedure.

Fixes #1529

To prevent additional signals from aborting program execution, signal
handling was moved to the beginning of the main function, this ensures
that signals stays registered for the entire shutdown procedure.

Fixes #1529
@mafredri mafredri self-assigned this Aug 18, 2022
@mafredri mafredri requested a review from a team August 18, 2022 08:53
//
// To get out of a graceful shutdown, the user can send
// SIGQUIT with ctrl+\ or SIGKILL with `kill -9`.
notifyCtx, notifyStop := signal.NotifyContext(ctx, interruptSignals...)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Naming this notifyCtx here means that during startup, and interrupt signal won't abort the process up until we start listening <-notifyCtx.Done().

The reason for this is that we have certain services that begin their shutdown procedure on context cancellation, but we want to control the order in which things are shut down.

I think it's acceptable that after starting, ctrl+c won't close coder server until the initial startup sequence is complete. But it's possible to work around this by monitoring the notifyCtx separately for parts of the startup where we want an early exit.

@mafredri mafredri merged commit 6a0f8ae into main Aug 18, 2022
@mafredri mafredri deleted the mafredri/server-signal-handling branch August 18, 2022 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coder server does not exit gracefully after single SIGHUP or SIGTERM
3 participants