Skip to content
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

auto-patchelf: don't use grep -q, as it causes Broken pipe #56958

Merged
merged 1 commit into from Mar 20, 2019

Conversation

danbst
Copy link
Contributor

@danbst danbst commented Mar 6, 2019

This rare sitation was caught when building zoom-us package:

automatically fixing dependencies for ELF files
/nix/store/71d65fplq44y9yn2fvkpn2d3hrszracd-auto-patchelf-hook/nix-support/setup-hook: line 213: echo: write error: Broken pipe
/nix/store/71d65fplq44y9yn2fvkpn2d3hrszracd-auto-patchelf-hook/nix-support/setup-hook: line 210: echo: write error: Broken pipe

The worst is that derivation continued and resulted into broken package:
#55566 (comment)

I hope, replacing grep -q with grep will remove this race condition.

cc @dasJ @aszlig as I see there was previously some attempt to fix Broken pipe in other places (#40598)

@danbst
Copy link
Contributor Author

danbst commented Mar 7, 2019

🤔 I see it doesn't cause mass rebuilds. Ok.

isExeResult="$(LANG=C readelf -h -l "$1" 2> /dev/null \
| grep '^ *Type: *EXEC\>\|^ *INTERP\>')"
# not using grep -q, because it can cause Broken pipe
[ -n "$isExeResult" ]
Copy link
Member

Choose a reason for hiding this comment

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

What about using grep -q -m1 instead? This should stop after a match has been found and not result in a broken pipe error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How can we verify this works? I can't reproduce original issue. The closest thing I could do is generate broken pipe from pip list:

$ (pip list | grep Package) 2>&1 | head
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Package                       Version                     

$ (pip list | grep -q Package) 2>&1 | head
Traceback (most recent call last):
  File "/nix/store/l95nkqp7bdimqnz9ixay1aahljzsz7vc-python-2.7.15/lib/python2.7/logging/__init__.py", line 892, in emit
    self.flush()
  File "/nix/store/l95nkqp7bdimqnz9ixay1aahljzsz7vc-python-2.7.15/lib/python2.7/logging/__init__.py", line 852, in flush
    self.stream.flush()
IOError: [Errno 32] Broken pipe
Logged from file list.py, line 234
Traceback (most recent call last):
  File "/nix/store/l95nkqp7bdimqnz9ixay1aahljzsz7vc-python-2.7.15/lib/python2.7/logging/__init__.py", line 892, in emit
    self.flush()

$ (pip list | grep -q -m1 Package) 2>&1 | head
Traceback (most recent call last):
  File "/nix/store/l95nkqp7bdimqnz9ixay1aahljzsz7vc-python-2.7.15/lib/python2.7/logging/__init__.py", line 892, in emit
    self.flush()
  File "/nix/store/l95nkqp7bdimqnz9ixay1aahljzsz7vc-python-2.7.15/lib/python2.7/logging/__init__.py", line 852, in flush
    self.stream.flush()
IOError: [Errno 32] Broken pipe
Logged from file list.py, line 234
Traceback (most recent call last):
  File "/nix/store/l95nkqp7bdimqnz9ixay1aahljzsz7vc-python-2.7.15/lib/python2.7/logging/__init__.py", line 892, in emit
    self.flush()

if isExecutable "$file"; then
# Skip if the executable is statically linked.
echo "$segmentHeaders" | grep -q "^ *INTERP\\>" || continue
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't ever result in a broken pipe error, at least in this context, so we don't need the workaround here.

Copy link
Member

Choose a reason for hiding this comment

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

@danbst: Hm, apparently according to your description it does. Do you have an output of strace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aszlig this is exactly the place where it failed, notice lines:

/nix/store/../setup-hook: line 213: echo: write error: Broken pipe
/nix/store/../setup-hook: line 210: echo: write error: Broken pipe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, missed your last comment. No, I can't reproduce this issue. It probably occurs only on high CPU load/slow CPUs.

@@ -207,10 +209,11 @@ autoPatchelf() {
isELF "$file" || continue
segmentHeaders="$(LANG=C readelf -l "$file")"
# Skip if the ELF file doesn't have segment headers (eg. object files).
echo "$segmentHeaders" | grep -q '^Program Headers:' || continue
# not using grep -q, because it can cause Broken pipe
[ -n "$(echo "$segmentHeaders" | grep '^Program Headers:')" ] || continue
Copy link
Member

Choose a reason for hiding this comment

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

Same as below.

@danbst
Copy link
Contributor Author

danbst commented Mar 12, 2019

@aszlig I'll merge this in a week if you don't object. I can't find shorter solution, which would work with pip list example above.

It requires rebuilding Qt, so I'll leave this for staging job.

@aszlig
Copy link
Member

aszlig commented Mar 13, 2019

It requires rebuilding Qt, so I'll leave this for staging job.

Since when does this need to rebuild Qt? Looking at the changed paths reported by ofborg, I can't see anything related to that, am I blind?

This rare sitation was caught when building zoom-us package:
```
automatically fixing dependencies for ELF files
/nix/store/71d65fplq44y9yn2fvkpn2d3hrszracd-auto-patchelf-hook/nix-support/setup-hook: line 213: echo: write error: Broken pipe
/nix/store/71d65fplq44y9yn2fvkpn2d3hrszracd-auto-patchelf-hook/nix-support/setup-hook: line 210: echo: write error: Broken pipe
```

The worst is that derivation continued and resulted into broken package:
NixOS#55566 (comment)

I hope, replacing `grep -q` with `grep` will remove this race condition.
@danbst danbst force-pushed the auto-patchelf-hook-broken-pipe branch from 1176fd3 to 87dfe89 Compare March 13, 2019 08:41
@danbst danbst changed the base branch from staging to master March 13, 2019 08:42
@danbst
Copy link
Contributor Author

danbst commented Mar 13, 2019

@aszlig you are correct, it was rebuilding Qt because of staging branch. All is good on master.

@danbst danbst merged commit de0612c into NixOS:master Mar 20, 2019
@danbst danbst deleted the auto-patchelf-hook-broken-pipe branch March 20, 2019 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants