-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
test: Fix pytest race in test_spawn_broken_pipe() #19470
test: Fix pytest race in test_spawn_broken_pipe() #19470
Conversation
cf579e4
to
3b2e5ad
Compare
(I realized I don't actually want no-test, as this test runs during rpm/deb package builds) |
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.
Feel free to merge this if the other approach doesn't work.
with open(f'/proc/{pid}/stat') as f: | ||
if f.read().split()[2] == 'Z': | ||
break | ||
time.sleep(0.1) |
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.
I'm generally okay with this approach, but you could also do something like:
# The process will exit soon — try writing to it until a write fails.
# Note: it's important that we observe .write() failing, so we do sync
# sleep to avoid being notified about the process exiting.
while not transport.is_closing():
transport.write(b'x')
time.sleep(0.1)
no?
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.
Ah, nice idea -- catch it from the write side instead of the process exit side. Seems to work fine!
Interesting: we thought long and hard about the race failing when the process exited too quickly (before the registration of the exit handler) but never considered the other direction :) |
The static `time.sleep(0.1)` was racy: On slow architectures like Debian mips [1] it repeatedly fails, and it even sometimes fails on GitHub actions. Keep writing until the transport closes, so that we are guaranteed to eventually run into a BrokenPipeError. Fixes cockpit-project#19469 [1] https://buildd.debian.org/status/logs.php?pkg=cockpit&ver=302-1&arch=mips64el
3b2e5ad
to
934c61c
Compare
The static
time.sleep(0.1)
was racy: On slow architectures like Debian mips [1] it repeatedly fails, and it even sometimes fails on GitHub actions.Keep writing until the transport closes, so that we are guaranteed to eventually run into a BrokenPipeError.
Fixes #19469
[1] https://buildd.debian.org/status/logs.php?pkg=cockpit&ver=302-1&arch=mips64el
Failures on GitHub: example 1, example 2