fix: prevent argv-mode runner deadlock on sandbox shutdown#151
Merged
Conversation
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
When
command.runtimeExecPolicy: "argv"is set on Linux, exiting a sandboxed agent could leave the outerfencewedged - prompt never returns, terminal must be closed. Reproduced on WSL2 (kernel 6.6) withfence -- bash; exit. Root cause: the runner's supervisor goroutine sits inioctl(SECCOMP_IOCTL_NOTIF_RECV), andclose(listenerFD)from another OS thread doesn't wake it, so the runner deadlocks waiting for the supervisor channel.Fix: park the supervisor in
ppoll([listenerFD, wakeFD])and wake it via aneventfd. A 2s bounded drain catches any future kernel where the eventfd path also misbehaves; on WSL2 today it never fires.Related: #148.
Changes
argvRunnerShutdown(eventfd + idempotentBegin()) inruntime_exec_argv_shutdown_linux.go.runLinuxArgvExecSupervisor:ppoll-then-ioctl viawaitForArgvExecNotification; handlesEAGAIN/EINTR/POLLHUP/EBADF.RunLinuxArgvExecRunnerFromEnv: restructured around the coordinator; oneBegin()covers all teardown paths with a 2s bounded drain that logs loudly if it fires.Setpgid: true).startLinuxArgvExecSignalForwarder: 1st SIGINT/SIGTERM -> bwrap; 2nd -> pgrp +Begin(); 3rd+ -> SIGKILL +Begin(). SIGWINCH unchanged.waitForArgvExecNotification.TestWaitForArgvExecNotification_WakeFromShutdown.Verification
pkill -9 bwrapmid-session also drains via the eventfd path (no timeout warning).Follow-up
Unify this signal forwarder with
startCommandWithSignalProxyincmd/fence/main.go(same escalation pattern)