Skip to content

Conversation

@fourdollars
Copy link
Contributor

@fourdollars fourdollars commented Jan 6, 2026

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'.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

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'.
Copilot AI review requested due to automatic review settings January 6, 2026 02:43
Copy link
Contributor

Copilot AI left a 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.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@MikeMcQuaid
Copy link
Member

@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.

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jan 6, 2026
Merged via the queue into Homebrew:main with commit 7674b00 Jan 6, 2026
36 checks passed
@fourdollars
Copy link
Contributor Author

fourdollars commented Jan 6, 2026

Have you followed the guidelines in our Contributing document?

But I have followed this. I am confused.
And it mentioned Open an issue on the formula's repository or on Homebrew/brew if it's not a formula-specific issue.

@MikeMcQuaid
Copy link
Member

@fourdollars Thanks for feedback, I will adjust.

@MikeMcQuaid
Copy link
Member

@fourdollars Thanks, opened #21391 to clarify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

brew will randomly output "grep: write error: Broken pipe" in the LXC container environment.

2 participants