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

Fix race condition in test_threaded #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielparks
Copy link
Contributor

Previously, test_threaded() started a thread that made two writes to each pipe. This had the potential for a race condition since the read might occur between the two writes. This changes it to make only one write for each pipe.

This maintains the two byte buffer despite reading only one byte just to confirm that it never somehow reads too much.

An alternate solution would be to fill buffers for each of the pipes and wait until they closed to check what was read. I thought that would be significantly more complicated.

I observed the race condition under Linux on Rust 1.71.0.

Previously, `test_threaded()` started a thread that made two writes to
each pipe. This had the potential for a race condition since the read
might occur between the two writes. This changes it to make only one
write for each pipe.

This maintains the two byte buffer despite reading only one byte just to
confirm that it never somehow reads too much.

An alternate solution would be to fill buffers for each of the pipes and
wait until they closed to check what was read. I thought that would be
significantly more complicated.

I observed the race condition under Linux on Rust 1.71.0.
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.

1 participant