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 non-thread-safe mutex access #4

Merged
merged 1 commit into from
Dec 11, 2019
Merged

Conversation

andriimakukha
Copy link

@andriimakukha andriimakukha commented Dec 11, 2019

When running SwiftWebSocket with the Thread Sanitizer, we noticed that there was a swift race condition when accessing the Manager's, or InnerWebSocket's mutex. Suspecting that this was simply a bug with the Thread Sanitizer we filed a Radar with Apple. Their response was this was actually a true positive and directed us to this article: http://www.russbishop.net/the-law.

Because Swifts & might allow for mutation on multiple threads, we need to allocate our own memory for the mutex to avoid a heap corruption.

tidwall/SwiftWebSocket PR#141
IanHoar/SwiftWebSocket PR#1

When running SwiftWebSocket with the Thread Sanitizer, we noticed that there was a swift race condition when accessing the Manager's, or InnerWebSocket's mutex. Suspecting that this was simply a bug with the Thread Sanitizer we filed a Radar with Apple.  Their response was this was actually a true positive and directed us to this article: http://www.russbishop.net/the-law.

Because Swifts `&` might allow for mutation on multiple threads, we need to allocate our own memory for the mutex to avoid a heap corruption.

tidwall/SwiftWebSocket PR#tidwall#141
IanHoar/SwiftWebSocket PR#1
Copy link

@davidjed davidjed left a comment

Choose a reason for hiding this comment

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

Good catch. Thanks!

@davidjed davidjed merged commit 9116346 into master Dec 11, 2019
@davidjed davidjed deleted the fix/andrii_m/mutex_warnings branch December 11, 2019 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants