fix(pipe): handle BrokenPipe errors gracefully and enable static linking#6
Conversation
|
!asset |
|
❌ PR asset build failed PR: #6 Please check the workflow run for details. Common issues:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a crash that occurs when path-git-format is used in Unix pipelines where downstream processes close the pipe early. The tool now exits gracefully with success status instead of crashing with a BrokenPipe error, aligning with standard Unix utility behavior.
Key changes:
- Modified error handling in
read_io_paths()to catch and gracefully handleBrokenPipeerrors - Ensures the tool exits with status code 0 when pipes are closed early by downstream processes
| if let Err(e) = writter.write_all(result_line.as_bytes()).await { | ||
| if e.kind() == io::ErrorKind::BrokenPipe { | ||
| return Ok(()); | ||
| } | ||
| return Err(e); | ||
| } | ||
| if let Err(e) = writter.write_all(b"\n").await { | ||
| if e.kind() == io::ErrorKind::BrokenPipe { | ||
| return Ok(()); | ||
| } | ||
| return Err(e); | ||
| } |
There was a problem hiding this comment.
The BrokenPipe error handling logic is duplicated three times. Consider extracting this pattern into a helper function to reduce code duplication and improve maintainability.
When used in pipelines with commands that close early (like head -n 1, fzf), the tool now exits gracefully instead of crashing with a BrokenPipe error. This is standard Unix behavior for pipeline commands. Co-authored-by: towry <8279858+towry@users.noreply.github.com>
e1f65bc to
6aaf12b
Compare
|
!asset |
|
✅ PR asset build completed successfully! PR: #6 📦 Download artifacts:
Quick test after download: tar -xzf path-git-format-*.tar.gz
printf "\$PWD" | ./path-git-format-*/path-git-format --format "{path}: {branch}" |
|
@copilot |
This is a dynamic library linking issue on macOS, unrelated to the broken pipe fix. The binary was built with dynamic linking to OpenSSL, but your system doesn't have the required version. To fix this, the project needs to enable static linking or vendored builds for git2/openssl. This is typically done in the build workflow, not in the source code. The broken pipe fix itself is working correctly. If you're building locally, you can use: cargo build --release --features git2/vendored-libgit2Or set this environment variable before building: export OPENSSL_STATIC=1
cargo build --release |
@copilot fix it |
Configure git2 with vendored-libgit2 and vendored-openssl features to statically link libgit2 and OpenSSL. This eliminates runtime dependencies on system OpenSSL libraries, fixing distribution issues on macOS and other platforms where the required OpenSSL version may not be available. Co-authored-by: towry <8279858+towry@users.noreply.github.com>
Fixed in commit 6ac3699. Configured git2 with Build verification on Linux shows no dynamic OpenSSL dependencies: ldd ./target/release/path-git-format | grep -i ssl
# (no output - OpenSSL is statically linked)The binary will now work on macOS without requiring specific OpenSSL versions to be installed. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
!asset |
|
✅ PR asset build completed successfully! PR: #6 📦 Download artifacts:
Quick test after download: tar -xzf path-git-format-*.tar.gz
printf "\$PWD" | ./path-git-format-*/path-git-format --format "{path}: {branch}" |
Problem
When
path-git-formatis used in pipelines with commands that close the pipe early (likehead -n 1,fzf, or similar), it crashes with aBrokenPipeerror instead of exiting gracefully:This is problematic because the tool cannot be reliably used in common Unix pipeline patterns where downstream processes may close the pipe after reading only the data they need.
Additionally, the binary had runtime dependencies on system OpenSSL libraries, causing distribution issues on macOS where the required OpenSSL version may not be available.
Solution
Broken Pipe Fix: Modified the
read_io_paths()function to catchBrokenPipeerrors during write operations and exit gracefully with success status. This is standard Unix behavior - when a downstream process closes the pipe, the upstream process should silently exit rather than crashing.The fix handles
BrokenPipeerrors in three places:Static Linking: Configured git2 dependency with
vendored-libgit2andvendored-opensslfeatures to statically link libgit2 and OpenSSL into the binary. This eliminates runtime dependencies on system OpenSSL libraries, making the binary fully self-contained and portable.Testing
Verified the broken pipe fix works correctly in multiple scenarios:
All scenarios now exit with status code 0 instead of crashing with a
BrokenPipeerror.Verified static linking:
Impact
read_io_paths()and dependency configuration inCargo.toml)grep,cat) when used in pipelinesFixes #4
Original prompt
Fixes #4
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.