Skip to content

Add a testcase for pthreads race conditions #12258

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 4 commits into from
Closed

Add a testcase for pthreads race conditions #12258

wants to merge 4 commits into from

Conversation

kripken
Copy link
Member

@kripken kripken commented Sep 17, 2020

This is a manual test for race conditions (disabled by default as it is
very long, and checks for a race condition so it is inherently flakey)
that are fixed in #12243 #12244 #12245

It passes after the fixes in those PRs. Without them, it tends to fail
after 100 iterations out of 1000, so at least for me locally it fails
pretty consistently before the fixes.

Note that that was with chrome. I saw the test fail on firefox too
but far more rarely. On node I never saw it fail. So it definitely is
sensitive to timing somehow.

@kripken kripken changed the title Add a testcase for pthreads race conditions fixed in #12243 #12244 #12245 Add a testcase for pthreads race conditions Sep 17, 2020
printf("%d %d\n", i, total);
for (int j = 0; j < 1024; j++) {
// allocation uses a mutex
auto* rd = new random_device();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't this be doing directly with the pthread_mutex APIs rather than indirectly depending on the implementation of "/dev/urandom"?

Of you could write the test directly against pthread.h we could also see if it occurs in musl's native configuration.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the use of /dev/random is not just for a mutex - it's also for proxying (all file I/O is proxied to the main thread). That involves more than just a mutex.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exactly, I was hoping for something a little more precise .... there is so much going on here its hard to know what this is testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, definitely... yeah, this is not a great testcase. But it's the smallest I've managed so far that shows the issue, which is really hard to reproduce (as shown by it existing since forever, apparently).

If I have time I can try to reduce this more. But it may be better to focus on figuring out the actual cause of the problem, as that may suggest a testcase. We don't need to merge this urgently and may never merge it I guess.

@tlively
Copy link
Member

tlively commented Sep 18, 2020

[Commenting just to bump any notifications on this higher in my inbox]

@kripken
Copy link
Member Author

kripken commented Sep 22, 2020

I have found the actual cause here, and will open a refactoring PR and then a fix PR shortly. The fix PR will contain a variant of this test, turned off by default.

@kripken kripken closed this Sep 22, 2020
@kripken kripken deleted the pthread4 branch September 22, 2020 23:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants