Conversation
`setup_open_file_with_contents` creates an anonymous pipe and writes the entire here-document / here-string payload into it before the reading command exists. That write can only complete while the payload still fits in the pipe buffer, so any larger payload blocks forever. Linux papered over this by growing the buffer to the payload size with F_SETPIPE_SZ. Every other platform kept the default buffer -- 4 KiB on Windows -- so a here-document past that threshold hangs the shell. The Linux path had gaps of its own: the fcntl is propagated with `?`, so it also failed outright for payloads over /proc/sys/fs/pipe-max-size (1 MiB by default for unprivileged processes) and for a zero-length payload. Keep the resize as a best-effort fast path and hand oversized payloads to a helper thread instead, so the write proceeds while the reader drains. The thread ends when the payload is consumed, or earlier with a broken pipe if the read end is dropped by a command that never reads its stdin. Found running an 88k-line bash CLI under brush on Windows: every `cat <<EOF`-based help function hung. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Performance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is Test Summary: bash-completion test suite
|
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.
Overview
Fix a deadlock when a here-document or here-string is larger than the pipe buffer.
This change was made by GitHub Copilot at my direction.
Details
setup_open_file_with_contentscurrently writes the complete payload into an anonymous pipe before the command that reads from it has been spawned. The write blocks indefinitely when the payload exceeds the available pipe capacity. This is especially visible on Windows, where the default pipe buffer is 4 KiB.This change:
F_SETPIPE_SZrejects an empty payload or one above the system pipe-size limit; andThe helper thread exits after the reader consumes the payload, or earlier on a broken pipe if the command closes the read end without consuming it.
Testing
cargo test --test brush-compat-tests -- herecargo xtask check fmtcargo clippy --package brush-core --package brush-shell --all-features --all-targets