-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
brew.sh: fix sporadic SIGPIPE in CPU feature check (Fixes #21365) #21366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The previous implementation used a pipeline: grep -E "^(flags|Features)" /proc/cpuinfo | grep -q "ssse3" This caused a race condition. If the second grep (grep -q) found a match and exited early, it closed the read end of the pipe. If the first grep was still writing to that pipe (processing subsequent lines of /proc/cpuinfo), it would receive a SIGPIPE and print 'grep: write error: Broken pipe' to stderr. This patch consolidates the logic into a single grep command: grep -qE '^(flags|Features).*\bssse3\b' /proc/cpuinfo This eliminates the pipeline entirely, preventing the broken pipe error while maintaining the same logic: verifying that 'ssse3' appears on a line starting with 'flags' or 'Features'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a race condition that caused sporadic SIGPIPE errors during CPU feature detection on Linux systems. The issue occurred when using a pipeline of two grep commands to check for SSSE3 CPU support.
Key Changes:
- Consolidated two piped grep commands into a single grep operation to eliminate the race condition
- Added word boundary anchors (
\b) to improve pattern matching precision
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
|
@fourdollars Note for future reference you don't need to open an issue if you're going to open a PR to fix it; just open the PR. |
But I have followed this. I am confused. |
|
@fourdollars Thanks for feedback, I will adjust. |
|
@fourdollars Thanks, opened #21391 to clarify. |
Fixes #21365
Closes #21359
The previous implementation used a pipeline:
grep -E "^(flags|Features)" /proc/cpuinfo | grep -q "ssse3"
This caused a race condition. If the second grep (grep -q) found a match and exited early, it closed the read end of the pipe. If the first grep was still writing to that pipe (processing subsequent lines of /proc/cpuinfo), it would receive a SIGPIPE and print 'grep: write error: Broken pipe' to stderr.
This patch consolidates the logic into a single grep command:
grep -qE '^(flags|Features).*\bssse3\b' /proc/cpuinfo
This eliminates the pipeline entirely, preventing the broken pipe error while maintaining the same logic: verifying that 'ssse3' appears on a line starting with 'flags' or 'Features'.
brew lgtm(style, typechecking and tests) with your changes locally?