Fix deadlock when bundle script hooks write large stderr output#5499
Open
simonfaltum wants to merge 2 commits into
Open
Fix deadlock when bundle script hooks write large stderr output#5499simonfaltum wants to merge 2 commits into
simonfaltum wants to merge 2 commits into
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
Contributor
Waiting for approvalBased on git history, these people are best suited to review:
Eligible reviewers: Suggestions based on git history. See OWNERS for ownership rules. |
Collaborator
|
Commit: 06046b5
22 interesting tests: 15 SKIP, 7 KNOWN
Top 29 slowest tests (at least 2 minutes):
|
Co-authored-by: Isaac
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.