Repository navigation
Handle graceful termination in gvisor ateom - #764
Benjamin Elder (BenTheElder) merged 4 commits into
Conversation
2849b1d to
997cd04
Compare
997cd04 to
e334f07
Compare
531af3c to
4aaf655
Compare
Benjamin Elder (BenTheElder)
left a comment
There was a problem hiding this comment.
review skill pass
[needs rebase as well, sorry, these files are high churn]
| // If the wait completed because the container actually exited (but with an error), | ||
| // we shouldn't send SIGKILL. | ||
| if !errors.Is(err, context.DeadlineExceeded) && !errors.Is(err, context.Canceled) { | ||
| slog.InfoContext(ctx, "Container exited with error status", slog.String("container", name), slog.Any("err", err)) |
There was a problem hiding this comment.
🤖 should-fix 🟡 – A failed runsc wait is indistinguishable from a clean exit here. Any non-context error from cmdWait reaches this branch and returns nil, so gracefulShutdown logs "All application containers stopped" and ateom exits without ever sending SIGKILL.
That is correct for a container that exited with a non-zero status. It is wrong when the wait itself failed and the container is still running: a runsc error, a container name that no longer exists, or the spurious ECHILD that cmdWait maps to success at cmd/ateom-gvisor/runsc.go:388. In those cases the actor loses the remainder of its grace period to the kubelet's SIGKILL, which is the outcome this PR exists to prevent.
Consider having cmdWait return a typed error that separates "container exited" from "wait failed", and escalating to SIGKILL on the latter.
There was a problem hiding this comment.
This isn't true. A clean exit would not return an error and be handled above. Any error returned from runsc wait is a failure to wait on the process, not a non-zero container status code.
That being said we probably should be returning an error here instead of nil, not that it changes the current behavior, but it's more appropriate if we want to add retry logic later.
| s.shuttingDown = true | ||
| session := s.activeSession | ||
| // Release the lock so that AteomService and respond to new RPCs. | ||
| s.lock.Unlock() |
There was a problem hiding this comment.
🤖 should-fix 🟡 – Dropping the lock lets CheckpointWorkload run during drain, which is the stated intent, but the two paths are not coordinated. By the time a suspend arrives, killContainer has already sent SIGTERM to every application container, and it will send SIGKILL once workloadGracePeriod expires — including in the middle of an in-flight runsc checkpoint.
CheckpointWorkload clears activeSession at cmd/ateom-gvisor/main.go:674, but gracefulShutdown captured the session pointer above, so it goes on to signal containers that were just checkpointed. TestGracefulWorkerTerminationSuspend only exercises a suspend that completes well inside the grace period, so neither case is covered.
Consider having the checkpoint path cancel the kill timer, or re-checking activeSession in killContainer before escalating.
Separately, the comment on the line above reads "so that AteomService and respond to new RPCs" — presumably "can respond".
There was a problem hiding this comment.
Re-setting the grace period during a checkpoint defeats the purpose. Even if we are checkpointing the container shouldn't be allowed to run for longer than the grace period.
4aaf655 to
f701d88
Compare
01b26e8
into
agent-substrate:main
Part of #23
Trap SIGTERM in the ateom, and forward SIGTERM to all application containers.
Once all application containers exit, ateom will exit itself.