Skip to content

Fix a potential race condition in StdlibUnittest #25136

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

Merged

Conversation

porglezomp
Copy link
Contributor

StdlibUnittest uses an AtomicBool to track whether a failure has ocurred in a test. Without these changes, expectFailure could have a false-positive failure due to a race condition on the _anyExpectFailed variable.

I believe the following interleaving of two threads A and B would trigger the issue:

A: loads false
A: stores false
B: loads false
A: stores true
B: stores false
A: loads false (after body)

which causes A to see a false-positive failure.

Fixes rdar://51247527
CC @lorentey

StdlibUnittest uses an AtomicBool to track whether a failure has ocurred
in a test. Before this, expectFailure could have a false-positive
failure due to a race condition on the _anyExpectFailed.

The following interleaving would trigger the issue:

A: loads false
A: stores false
B: loads false
A: stores true
B: stores false
A: loads false (after body)

This causes A to see a false-positive failure.
Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

Looks good to me! 👍

@lorentey
Copy link
Member

@swift-ci test

@shahmishal shahmishal merged commit d543dd9 into swiftlang:master May 31, 2019
@porglezomp porglezomp deleted the fix/stdlib-unittest-race branch May 31, 2019 21:19
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.

3 participants