Skip to content

feat(agent): Handle signals and shutdown gracefully - #5914

Merged
mafredri merged 2 commits into
mainfrom
mafredri/feat-handle-agent-signals
Jan 30, 2023
Merged

mafredri merged 2 commits into
mainfrom
mafredri/feat-handle-agent-signals

Conversation

@mafredri

Copy link
Copy Markdown
Member

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

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
@mafredri mafredri self-assigned this Jan 30, 2023
Comment thread cli/agent.go
Comment on lines +57 to +62
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)

@mafredri mafredri Jan 30, 2023 •

Copy link
Copy Markdown
Member Author

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.

@mtojek mtojek left a comment

Copy link
Copy Markdown
Member

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.

@mafredri
mafredri merged commit cf8d402 into main Jan 30, 2023
@mafredri
mafredri deleted the mafredri/feat-handle-agent-signals branch January 30, 2023 13:59
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants