Skip to content

shim: bound runsc calls with a 30s deadline and WaitDelay - #14549

Merged
copybara-service[bot] merged 1 commit into
gvisor:masterfrom
NahumLitvin:fix/shim-bounded-kill
Sep 24, 2026
Merged

copybara-service[bot] merged 1 commit into
gvisor:masterfrom
NahumLitvin:fix/shim-bounded-kill

Conversation

@NahumLitvin

@NahumLitvin NahumLitvin commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

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

@konstantin-s-bogom

Copy link
Copy Markdown
Member

most of them cadvisor Stats calls

If most of them were Stats calls, maybe the deadline should also be applied to Stats? See if there's any other commands.

Comment thread pkg/shim/v1/proc/init.go Outdated
Comment on lines +430 to +435
// 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)
}

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.

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.

@NahumLitvin

Copy link
Copy Markdown
Contributor Author

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.

@NahumLitvin

Copy link
Copy Markdown
Contributor Author

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.

@konstantin-s-bogom

Copy link
Copy Markdown
Member

Sure, let's focus this CL on just establishing a deadline on those 3 ops

@NahumLitvin

Copy link
Copy Markdown
Contributor Author

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.

@NahumLitvin NahumLitvin changed the title shim: bound runsc kill, escalate to killing the sandbox process shim: bound runsc kill, Stats and Status with a 30s deadline Sep 17, 2026
@NahumLitvin
NahumLitvin force-pushed the fix/shim-bounded-kill branch 3 times, most recently from 4d1b4d4 to 1a0552a Compare September 21, 2026 09:52
@NahumLitvin NahumLitvin changed the title shim: bound runsc kill, Stats and Status with a 30s deadline shim: bound runsc calls with a 30s deadline and WaitDelay Sep 21, 2026
@NahumLitvin

Copy link
Copy Markdown
Contributor Author

CI here only runs check-changes and the CLA, so for the record I ran both bazel targets against this base:

//pkg/shim/v1/proc:proc_test         PASSED in 2.5s
//pkg/shim/v1/runsccmd:runsccmd_test PASSED in 0.2s

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
@konstantin-s-bogom konstantin-s-bogom added the ready to pull Causes the PR to be imported into Google. Will be removed soon. label Sep 23, 2026
copybara-service Bot pushed a commit that referenced this pull request Sep 24, 2026
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
copybara-service Bot pushed a commit that referenced this pull request Sep 24, 2026
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
copybara-service Bot pushed a commit that referenced this pull request Sep 24, 2026
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
copybara-service Bot pushed a commit that referenced this pull request Sep 24, 2026
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
copybara-service Bot pushed a commit that referenced this pull request Sep 24, 2026
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
@copybara-service
copybara-service Bot merged commit 20f4b91 into gvisor:master Sep 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull Causes the PR to be imported into Google. Will be removed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants