- Notifications
You must be signed in to change notification settings - Fork924
feat(agent): Handle signals and shutdown gracefully#5914
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This change allows the agent to handle common shutdown signals likeinterrupt, hangup and terminate and initiate a graceful shutdown.As long as terraform providers initiate graceful shutdowns via theaforementioned signals, things like SSH connections will be closedimmediately on shutdown instead of being left hanging/timing out due tothe agent being abruptly killed.Refs:#4677,#5901
logWriter := &lumberjack.Logger{ | ||
Filename: filepath.Join(os.TempDir(), "coder-agent-init.log"), | ||
MaxSize: 5, // MB | ||
} | ||
defer logWriter.Close() | ||
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This change might not actually be needed, but it feels safer than having both PID 1 and the forked process share an opened file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It's sad that we can't put a unit test here in case somebody will try to refactor it in the future. Apart from this, LGTM.
This change allows the agent to handle common shutdown signals like
interrupt, hangup and terminate and initiate a graceful shutdown.
As long as terraform providers initiate graceful shutdowns via the
aforementioned signals, things like SSH connections will be closed
immediately on shutdown instead of being left hanging/timing out due to
the agent being abruptly killed.
Refs:#4677,#5901