Repository navigation
Conversation
…n deadline MaxExecutionTime did not bound Run while a builtin waited on an *os.File stdin pipe that never sends, the setup the docs recommend: cat, head, tail, grep, wc, sort, uniq, tr, sed, cut, strings, xargs and jq hung forever. Only read, awk and sha256sum had their own way to wake up at the deadline. Run now binds the runner's stdin to the run's context once: when the context ends, a watchdog sets an expired read deadline on the file, which wakes any blocked Read with os.ErrDeadlineExceeded. The file is never closed and no bytes are read on the caller's behalf, and the deadline is cleared when Run returns. Files without read deadlines (regular files, /dev/null, anonymous pipes on Windows) are left alone. Found by Jacob Hayes with patina (https://github.com/JacobHayes/patina). Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Anonymous pipes on Windows have no read deadlines, the documented limit of this fix; read, awk and sha256sum still run there. Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
What
MaxExecutionTimedidn't boundRunwhile a builtin waited on an*os.Filestdin pipe that never sends, which is the setup the docs recommend. 13 builtins hung forever:cat,head,tail,grep,wc,sort,uniq,tr,sed,cut,strings,xargsandjq. Onlyread,awkandsha256sumhad their own way to wake up at the deadline.Runnow binds the runner's stdin to the run's context once (interp/stdin_deadline.go). When the context ends, a watchdog sets an already-expired read deadline on the file, which wakes any blockedReadwithos.ErrDeadlineExceeded.Runreturns./dev/null) are left alone.Limits, also noted in
SHELL_FEATURES.md:*os.Fileisn't covered.Credit
Found by Jacob Hayes with his deterministic-simulation tool patina (finding #5: a never-sending pipe leg plus a never-returns detector, about 140 runs). Findings thread: https://dd.slack.com/archives/D0AC8RLB21J/p1793475631273749
Tests
interp/stdin_pipe_deadline_test.go:TestMaxExecutionTimeBoundsBuiltinBlockedOnStdinPipe: each of the 16 stdin-reading builtins gets an idleos.Pipestdin and a 200msMaxExecutionTime, and must returncontext.DeadlineExceededwithin 5s. On main exactly the 13 reported builtins fail.TestStdinPipeDeadlineDoesNotLeakOrStealBytes: after a normal run no deadline is left on the pipe and later bytes are still readable.On Windows the test skips the 13 cases that rely on a read deadline (the limit above);
read,awkandsha256sumstill run there. Passes with-race.GOOS=windows/darwin go vet ./interp/is clean.go test ./...passes exceptTestPSPentestLargePIDListDoesNotHanginbuiltins/ps, which fails the same way on clean main on this host.🤖 Generated with Claude Code