Fix deadlock when bundle script hooks write large stderr output#5499
Merged
Conversation
Script hook output was read sequentially (stdout to EOF, then stderr), so a hook writing more than the OS pipe buffer (~64KiB) to stderr while stdout was still open blocked forever. Spool stderr to memory in a goroutine while streaming stdout, then log it after stdout EOF, keeping the existing output order. Co-authored-by: Isaac
Collaborator
Integration test reportCommit: e4cb1f7
30 interesting tests: 15 SKIP, 8 flaky, 7 KNOWN
Top 50 slowest tests (at least 2 minutes):
|
Co-authored-by: Isaac
janniklasrose
approved these changes
Jun 17, 2026
Collaborator
Integration test reportCommit: 0437746
626 interesting tests: 549 MISS, 60 FAIL, 11 KNOWN, 4 PANIC, 2 SKIP
Top 50 slowest tests (at least 2 minutes):
|
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.
Why
Found during a full-repo review of the CLI. Bundle script hooks (
experimental.scripts) can deadlock a deploy forever. Hook output was read sequentially: stdout to EOF first, then stderr. A hook that writes more than the OS pipe buffer (about 64KiB) to stderr while stdout is still open blocks on the stderr write and never closes stdout, so the script and the CLI wait on each other indefinitely.Changes
Before, stderr was only read after stdout reached EOF (via
io.MultiReader); now stderr is drained concurrently, so the hook can never block on a full stderr pipe. Inbundle/scripts/scripts.go, a goroutine spools stderr to memory while stdout is streamed line by line, and the spooled stderr is logged after stdout EOF. This keeps the existing stdout-then-stderr output order (no interleaving), so observable output is unchanged for hooks that complete today. The line logging loop is extracted into alogOutputhelper and still emits a final line without a trailing newline.Test plan
TestExecuteLargeStderrOutputDoesNotDeadlockwrites well over the pipe buffer to stderr before touching stdout; verified it deadlocks against the previous implementation (killed by the test context after 60s) and passes in ~0.05s with the fixgo test -race ./bundle/scriptspasses, including the existing no-trailing-newline testacceptance/bundle/scriptspass for both engines with no output changes./task fmt-q,./task lint-q,./task checksall cleanThis pull request and its description were written by Isaac.