fix(sandbox): escalate kill-all to SIGKILL when a task ignores SIGTERM#4516
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(sandbox): escalate kill-all to SIGKILL when a task ignores SIGTERM#4516pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
TaskManager.kill() and killByLogName() both follow up a SIGTERM with a SIGKILL after 3s if the task is still running, but killAll() sent a bare SIGTERM with no escalation — a task whose process traps or ignores TERM (a stuck subprocess, a shell with a TERM trap) would survive a kill-all call indefinitely.
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
packages/sandbox/daemon/process/task-manager.ts(recent churn area).TaskManager.kill()andkillByLogName()both escalate toSIGKILLafter 3s if the task is still running post-SIGTERM, butkillAll()only sent a bareSIGTERMwith no follow-up. A task whose process ignores/trapsTERM(a stuck subprocess, a shell that trapsTERM) would survive aPOST /_sandbox/tasks/kill-allcall forever instead of being force-killed like every other kill path.Failure scenario + regression test
Added
packages/sandbox/daemon/process/task-manager.test.ts: spawns a task runningtrap '' TERM; while true; do :; done(a busy-loop shell that ignores TERM), callskillAll(), and asserts it ends upkilled. On currentmainthis test times out (5s) because the task never dies; with the fix it passes in ~3s (aSIGKILLfires after the 3s grace period).How to verify
Checks run locally
bun test packages/sandbox/daemon/process/task-manager.test.ts— 10 passcd packages/sandbox && bun run check(tsc --noEmit) — cleanbun run fmt— cleanFull CI will run the rest of the suite.
Summary by cubic
Escalates
TaskManager.killAll()to sendSIGKILLafter 3s if a task ignoresSIGTERM, matching other kill paths. This makes POST/_sandbox/tasks/kill-allreliably stop stuck or TERM-trapping tasks.packages/sandbox/daemon/process/task-manager.ts, followSIGTERMwithSIGKILLafter 3s when a task is still running.packages/sandbox/daemon/process/task-manager.test.tsthat spawns a shell loop trappingTERMand assertskillAll()results inkilled.Written for commit 340a877. Summary will update on new commits.