Repository navigation
fix(sandbox): bound runtime shutdown after SIGTERM - #5279
Merged
Merged
Conversation
After a termination signal the boundary kills the workload and stops serving, then drops its process runtime. The drop waited without a limit for every blocking task. The supervisor keeps an agent `Wait` exchange open for the life of the sandbox, and that exchange blocks on a condition variable that only the agent's async reaper wakes. When the runtime shutdown cancelled the reaper before it recorded the exit, the `Wait` never returned and the process stayed alive until SIGKILL, so every delete or stop took the full termination grace period. Stop the process runtime with a two-second bound on every return path from `serve`. Workload kill and reaping are unchanged. Part of #5025 Signed-off-by: divesh <dgude@nvidia.com>
github-actions
Bot
requested review from
TaylorMutch,
drew,
purp and
shiju-nv
November 4, 2026 21:47
7 of 8 tasks
Collaborator
Author
|
/ok to test 0037efe |
6 tasks
shiju-nv
reviewed
Nov 5, 2026
This was referenced Nov 5, 2026
Run the child through run_isolated so a stall during setup fails the test instead of hanging it, and have the fake supervisor send SIGTERM once its exchanges are parked. Signed-off-by: divesh <dgude@nvidia.com>
Collaborator
Author
|
/ok to test f339b5b |
shiju-nv
approved these changes
Nov 6, 2026
2 tasks
Member
|
Thanks for the fix. The follow-up for the root cause (the agent |
|
Label |
elezar
enabled auto-merge
November 6, 2026 13:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After SIGTERM,
openshell-sandboxcould stay alive until the container runtime SIGKILLed it, so every Kubernetes sandbox delete waited out the pod's 30 s termination grace period. The boundary now stops its process runtime within two seconds after it stops serving.Related Issue
Part of #5025. This PR fixes the
openshell-sandboxhalf; #5025 stays open for the supervisor pod, which can still wait out the grace period.Changes
run_boundaryserves throughserve_then_stop, which callsshutdown_timeoutwith a 2 s bound afterservereturns, on every return path. Dropping the runtime used to wait for blocking tasks with no limit.servereturns.sigterm_exits_while_the_supervisor_holds_an_exchange_open. It runs the boundary in a child process behind a fake supervisor that starts an agent and keeps aWaitand anAcceptNetworkexchange open, sends SIGTERM, and requires an exit within 10 s.Root cause: the supervisor keeps an agent
Waitexchange open for the life of the sandbox.ManagedProcess::waitblocks on a condition variable that only the agent's async reaper task wakes. When the runtime shutdown cancelled the reaper before it recorded the exit,Waitnever returned, and the main thread stayed inBlockingPool::shutdownunderdrop(Runtime)until SIGKILL. gdb on a hung run showed the only other runtime thread inserve_one→dispatch→BoundaryRuntime::wait→ManagedProcess::wait.Release Notes
Deleting a sandbox on Kubernetes no longer waits out the pod's 30-second termination grace period.
Testing
cargo clippy -p openshell-sandbox --all-targets -- -D warnings(also with--features perf-harness),mise run rust:format:check, andcargo test -p openshell-sandbox(290 tests) passManual, on k3s with the Kubernetes driver (30 s grace period, a supervisor pod per sandbox), changing only the sandbox runtime image:
openshell sandbox deleteopenshell sandbox stopStop was already fast in this setup because the driver stops the supervisor pod first.
Follow-ups:
Waituses the full 2 s bound every time. Waiting up to the existing 2 s reap timeout for the killed agent beforeservereturns, or recording the exit outside the cancellable reaper, would make the exit immediate.sandbox delete.Checklist