fix: stdout/stderr interleaving in build output (issue #2511) - #2630
Open
wolfv wants to merge 3 commits into
Open
fix: stdout/stderr interleaving in build output (issue #2511)#2630wolfv wants to merge 3 commits into
wolfv wants to merge 3 commits into
Conversation
Build script output could appear in a random order because stdout and stderr were read from two separate pipes and merged with `tokio::select!`, which picks whichever stream has a line ready. The relative ordering of the two independently buffered streams cannot be recovered that way. Point both the child's stdout and stderr at a single OS pipe so the kernel interleaves them in the exact order they were written, then read that one stream. This is the same effect as the documented `exec 2>&1` workaround, applied uniformly regardless of the interpreter running inside the wrapper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TTZZd4NWFdMcEnGyWwyefx
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…2511-owmedn # Conflicts: # Cargo.lock # py-rattler-build/rust/Cargo.lock
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
This PR fixes a critical issue where stdout and stderr from build processes were appearing in random order in the output logs. The problem was caused by reading stdout and stderr as separate streams and racing them with
tokio::select!, which couldn't recover the true ordering due to independent buffering.Key Changes
tokio::select!in favor of reading from a single merged pipestd::fs::Filefor both Unix and Windowsstdout_logandstderr_logto a singleoutput_log, with stderr now empty (all output merged into stdout)test_stdout_stderr_interleaved_in_write_order()that runs 20 iterations to verify consistent orderingImplementation Details
os_pipecrate to create OS-level pipes that preserve write orderingtokio::fs::Fileto perform async reads on the blocking thread poolexec 2>&1workaround but applied uniformly regardless of the shell interpreterhttps://claude.ai/code/session_01TTZZd4NWFdMcEnGyWwyefx