Repository navigation
shim: bound runsc calls with a 30s deadline and WaitDelay - #14549
Conversation
515c43d to
564f69a
Compare
If most of them were Stats calls, maybe the deadline should also be applied to Stats? See if there's any other commands. |
| // Sandbox did not answer within killTimeout: kill its process directly. | ||
| log.L.Warningf("`runsc kill` for container %q timed out after %v; killing sandbox process %d", p.id, killTimeout, p.pid) | ||
| if p.pid > 0 { | ||
| if err := unix.Kill(p.pid, unix.SIGKILL); err != nil && err != unix.ESRCH { | ||
| log.L.Warningf("Failed to kill sandbox process %d: %v", p.pid, err) | ||
| } |
There was a problem hiding this comment.
This is pretty dangerous, what happens if the workload is doing something legitimate that's blocking the kill, like taking a large checkpoint which is taking over 30 seconds? This can be triggered by other containers exiting: https://cs.opensource.google/gvisor/gvisor/+/master:pkg/shim/v1/runsc/service.go;drc=4b9e98bee7b9c2a38afe76365bb9694aee523882;l=603 , in which case killAllLocked now takes down the entire sandbox.
I agree that the timeout to not hold the mutex makes sense, but I am not convinced about this yet.
|
fair point, i had KillAll in my head as teardown only. it fires from the exit handler too when an init process exits, so on a busy sandbox this would take out healthy containers. same over-reaction as in #14201, one layer up. il drop the escalation here and keep the 30s limit on kill plus WaitDelay, which is what frees the mutex and ends the goroutine pileup we saw. escalation goes back to #14548. unless you would rather keep it scoped to explicit teardown only, with the exit handler untouched. say which and il push. |
|
checked the others. Stats and Status are the ones i would add: same mutex, and both run on a timer, cadvisor every 10s and kubelet PLEG. checkProcesses also takes that mutex, so a stuck Stats delays exit events for the whole shim, not just the container that hung. il give those two the same 30s. Update, Delete, Start, Restore and CheckpointSandbox have no limit either, but they run once per lifecycle and some are slow by nature, so id leave them out for now. tell me if you want them in. |
|
Sure, let's focus this CL on just establishing a deadline on those 3 ops |
564f69a to
02c2646
Compare
|
Rebased on master. This is now just the 30s deadline on Kill, Stats and Status. You were right about killAllLocked, it also runs from the exit handler, so a slow checkpoint would have taken healthy containers with it. killAllLocked still goes through killRuntime, so the FUSE watchdog master gained since I branched stays in place. New init_kill_test.go has a test that fails if the shim signals the sandbox pid. Escalation moved to #14548. |
02c2646 to
df1b47b
Compare
4d1b4d4 to
1a0552a
Compare
|
CI here only runs check-changes and the CLA, so for the record I ran both bazel targets against this base: Both mutation checked. Put the sandbox kill back and proc_test fails in 0.5s on the pipe read. Delete cmd.WaitDelay and runsccmd_test times out at 60s. |
Init.mu is held across every runsc invocation, so one hung `runsc kill` blocks every later Kill, Stats and Status call on that container. In the dump attached to gvisor#14405 that pileup reached 45,646 goroutines and 610MB of shim RSS over five days, most of them cadvisor Stats calls whose clients had timed out long before. Give each of the three operations a 30s context deadline so a wedged sandbox releases the mutex, and set WaitDelay on runsc commands so a killed command cannot leave Wait blocked on fds a grandchild inherited. Per review this no longer escalates to killing the sandbox process. KillAll also runs from the exit handler when an init process exits, so that escalation would take out healthy containers in the same sandbox. It is tracked in gvisor#14548 instead. Updates gvisor#14548 Assisted-by: Claude Code
1a0552a to
9d1aa3e
Compare
This is the shim half of #14548. When the sandbox control server stopped answering (#14405, #14408), each `runsc kill` ran with no limit and the shim held the container lock across the call. In one production dump 45,646 goroutines sat behind that lock, most of them cadvisor `Stats` calls whose clients had long since timed out, 610MB shim RSS after 5 days, and kubelet retried into it for days. Two changes: - `Kill`, `Stats` and `Status` each run under a 30s context, so a wedged sandbox releases `Init.mu` instead of holding it for good - runsc commands get `WaitDelay`, so a killed command cannot leave `Wait` blocked on fds a grandchild inherited The sentry-side fix for the original hang merged in #14201. This covers the shim for when a sandbox finds a new way to stop answering. Not covered: `Init.Update` and `Init.Delete` hold `p.mu` across a runsc call with no bound too, same shape as `Status` and `Stats`. The pileup can come back through either. I left them out to keep this reviewable. On the number: `kill`'s own retry loop already gives up after 1s, 10s under `FuseAbort`, so 30s sits well clear of anything a healthy sandbox does. It is there to catch the sandbox that never answers, not to set a latency target. An earlier revision escalated to SIGKILL on the sandbox process once the 30s expired. That is out, per review: `killAllLocked` also runs from the exit handler when an init process exits, so the escalation would have taken healthy containers in the same sandbox with it. #14548 tracks it instead. Tests: `init_kill_test.go` covers a wedged `runsc` for Kill, KillAll, Stats and Status, and checks that the sandbox process survives KillAll. `runsc_test.go` covers the fd case: a fake runsc that exits while a child still holds the pipe `cmdOutput` handed it, which leaves `Wait` stuck without `WaitDelay`. Updates #14548 Assisted-by: Claude Code FUTURE_COPYBARA_INTEGRATE_REVIEW=#14549 from NahumLitvin:fix/shim-bounded-kill 9d1aa3e PiperOrigin-RevId: 987096412
This is the shim half of #14548. When the sandbox control server stopped answering (#14405, #14408), each `runsc kill` ran with no limit and the shim held the container lock across the call. In one production dump 45,646 goroutines sat behind that lock, most of them cadvisor `Stats` calls whose clients had long since timed out, 610MB shim RSS after 5 days, and kubelet retried into it for days. Two changes: - `Kill`, `Stats` and `Status` each run under a 30s context, so a wedged sandbox releases `Init.mu` instead of holding it for good - runsc commands get `WaitDelay`, so a killed command cannot leave `Wait` blocked on fds a grandchild inherited The sentry-side fix for the original hang merged in #14201. This covers the shim for when a sandbox finds a new way to stop answering. Not covered: `Init.Update` and `Init.Delete` hold `p.mu` across a runsc call with no bound too, same shape as `Status` and `Stats`. The pileup can come back through either. I left them out to keep this reviewable. On the number: `kill`'s own retry loop already gives up after 1s, 10s under `FuseAbort`, so 30s sits well clear of anything a healthy sandbox does. It is there to catch the sandbox that never answers, not to set a latency target. An earlier revision escalated to SIGKILL on the sandbox process once the 30s expired. That is out, per review: `killAllLocked` also runs from the exit handler when an init process exits, so the escalation would have taken healthy containers in the same sandbox with it. #14548 tracks it instead. Tests: `init_kill_test.go` covers a wedged `runsc` for Kill, KillAll, Stats and Status, and checks that the sandbox process survives KillAll. `runsc_test.go` covers the fd case: a fake runsc that exits while a child still holds the pipe `cmdOutput` handed it, which leaves `Wait` stuck without `WaitDelay`. Updates #14548 Assisted-by: Claude Code FUTURE_COPYBARA_INTEGRATE_REVIEW=#14549 from NahumLitvin:fix/shim-bounded-kill 9d1aa3e PiperOrigin-RevId: 987096412
This is the shim half of #14548. When the sandbox control server stopped answering (#14405, #14408), each `runsc kill` ran with no limit and the shim held the container lock across the call. In one production dump 45,646 goroutines sat behind that lock, most of them cadvisor `Stats` calls whose clients had long since timed out, 610MB shim RSS after 5 days, and kubelet retried into it for days. Two changes: - `Kill`, `Stats` and `Status` each run under a 30s context, so a wedged sandbox releases `Init.mu` instead of holding it for good - runsc commands get `WaitDelay`, so a killed command cannot leave `Wait` blocked on fds a grandchild inherited The sentry-side fix for the original hang merged in #14201. This covers the shim for when a sandbox finds a new way to stop answering. Not covered: `Init.Update` and `Init.Delete` hold `p.mu` across a runsc call with no bound too, same shape as `Status` and `Stats`. The pileup can come back through either. I left them out to keep this reviewable. On the number: `kill`'s own retry loop already gives up after 1s, 10s under `FuseAbort`, so 30s sits well clear of anything a healthy sandbox does. It is there to catch the sandbox that never answers, not to set a latency target. An earlier revision escalated to SIGKILL on the sandbox process once the 30s expired. That is out, per review: `killAllLocked` also runs from the exit handler when an init process exits, so the escalation would have taken healthy containers in the same sandbox with it. #14548 tracks it instead. Tests: `init_kill_test.go` covers a wedged `runsc` for Kill, KillAll, Stats and Status, and checks that the sandbox process survives KillAll. `runsc_test.go` covers the fd case: a fake runsc that exits while a child still holds the pipe `cmdOutput` handed it, which leaves `Wait` stuck without `WaitDelay`. Updates #14548 Assisted-by: Claude Code FUTURE_COPYBARA_INTEGRATE_REVIEW=#14549 from NahumLitvin:fix/shim-bounded-kill 9d1aa3e PiperOrigin-RevId: 987096412
This is the shim half of #14548. When the sandbox control server stopped answering (#14405, #14408), each `runsc kill` ran with no limit and the shim held the container lock across the call. In one production dump 45,646 goroutines sat behind that lock, most of them cadvisor `Stats` calls whose clients had long since timed out, 610MB shim RSS after 5 days, and kubelet retried into it for days. Two changes: - `Kill`, `Stats` and `Status` each run under a 30s context, so a wedged sandbox releases `Init.mu` instead of holding it for good - runsc commands get `WaitDelay`, so a killed command cannot leave `Wait` blocked on fds a grandchild inherited The sentry-side fix for the original hang merged in #14201. This covers the shim for when a sandbox finds a new way to stop answering. Not covered: `Init.Update` and `Init.Delete` hold `p.mu` across a runsc call with no bound too, same shape as `Status` and `Stats`. The pileup can come back through either. I left them out to keep this reviewable. On the number: `kill`'s own retry loop already gives up after 1s, 10s under `FuseAbort`, so 30s sits well clear of anything a healthy sandbox does. It is there to catch the sandbox that never answers, not to set a latency target. An earlier revision escalated to SIGKILL on the sandbox process once the 30s expired. That is out, per review: `killAllLocked` also runs from the exit handler when an init process exits, so the escalation would have taken healthy containers in the same sandbox with it. #14548 tracks it instead. Tests: `init_kill_test.go` covers a wedged `runsc` for Kill, KillAll, Stats and Status, and checks that the sandbox process survives KillAll. `runsc_test.go` covers the fd case: a fake runsc that exits while a child still holds the pipe `cmdOutput` handed it, which leaves `Wait` stuck without `WaitDelay`. Updates #14548 Assisted-by: Claude Code FUTURE_COPYBARA_INTEGRATE_REVIEW=#14549 from NahumLitvin:fix/shim-bounded-kill 9d1aa3e PiperOrigin-RevId: 987096412
This is the shim half of #14548. When the sandbox control server stopped answering (#14405, #14408), each `runsc kill` ran with no limit and the shim held the container lock across the call. In one production dump 45,646 goroutines sat behind that lock, most of them cadvisor `Stats` calls whose clients had long since timed out, 610MB shim RSS after 5 days, and kubelet retried into it for days. Two changes: - `Kill`, `Stats` and `Status` each run under a 30s context, so a wedged sandbox releases `Init.mu` instead of holding it for good - runsc commands get `WaitDelay`, so a killed command cannot leave `Wait` blocked on fds a grandchild inherited The sentry-side fix for the original hang merged in #14201. This covers the shim for when a sandbox finds a new way to stop answering. Not covered: `Init.Update` and `Init.Delete` hold `p.mu` across a runsc call with no bound too, same shape as `Status` and `Stats`. The pileup can come back through either. I left them out to keep this reviewable. On the number: `kill`'s own retry loop already gives up after 1s, 10s under `FuseAbort`, so 30s sits well clear of anything a healthy sandbox does. It is there to catch the sandbox that never answers, not to set a latency target. An earlier revision escalated to SIGKILL on the sandbox process once the 30s expired. That is out, per review: `killAllLocked` also runs from the exit handler when an init process exits, so the escalation would have taken healthy containers in the same sandbox with it. #14548 tracks it instead. Tests: `init_kill_test.go` covers a wedged `runsc` for Kill, KillAll, Stats and Status, and checks that the sandbox process survives KillAll. `runsc_test.go` covers the fd case: a fake runsc that exits while a child still holds the pipe `cmdOutput` handed it, which leaves `Wait` stuck without `WaitDelay`. Updates #14548 Assisted-by: Claude Code FUTURE_COPYBARA_INTEGRATE_REVIEW=#14549 from NahumLitvin:fix/shim-bounded-kill 9d1aa3e PiperOrigin-RevId: 987096412
This is the shim half of #14548. When the sandbox control server stopped answering (#14405, #14408), each
runsc killran with no limit and the shim held the container lock across the call. In one production dump 45,646 goroutines sat behind that lock, most of them cadvisorStatscalls whose clients had long since timed out, 610MB shim RSS after 5 days, and kubelet retried into it for days.Two changes:
Kill,StatsandStatuseach run under a 30s context, so a wedged sandbox releasesInit.muinstead of holding it for goodWaitDelay, so a killed command cannot leaveWaitblocked on fds a grandchild inheritedThe sentry-side fix for the original hang merged in #14201. This covers the shim for when a sandbox finds a new way to stop answering.
Not covered:
Init.UpdateandInit.Deleteholdp.muacross a runsc call with no bound too, same shape asStatusandStats. The pileup can come back through either. I left them out to keep this reviewable.On the number:
kill's own retry loop already gives up after 1s, 10s underFuseAbort, so 30s sits well clear of anything a healthy sandbox does. It is there to catch the sandbox that never answers, not to set a latency target.An earlier revision escalated to SIGKILL on the sandbox process once the 30s expired. That is out, per review:
killAllLockedalso runs from the exit handler when an init process exits, so the escalation would have taken healthy containers in the same sandbox with it. #14548 tracks it instead.Tests:
init_kill_test.gocovers a wedgedrunscfor Kill, KillAll, Stats and Status, and checks that the sandbox process survives KillAll.runsc_test.gocovers the fd case: a fake runsc that exits while a child still holds the pipecmdOutputhanded it, which leavesWaitstuck withoutWaitDelay.Updates #14548
Assisted-by: Claude Code