Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Fix non-thread-safe mutex access #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

IanHoar
Copy link

@IanHoar IanHoar commented Apr 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.

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.
@bielikb
Copy link

bielikb commented May 26, 2019

Will this fix make it to the release?

@helje5
Copy link

helje5 commented Jul 30, 2019

Works fine for me, ran into the same issue.

@iwasrobbed-ks
Copy link

👍 confirmed this fixed an issue seen in the thread sanitizer

moozzyk added a commit to moozzyk/SignalR-Client-Swift that referenced this pull request Sep 8, 2019
SwiftWebSocket has a threading issue described in
#37 (comment).
There is a PR in the SwiftWebSocket (tidwall/SwiftWebSocket#141) repo to fix the problem but it does
not seem like it is going to be merged anytime soon so applying the fix
locally.
A nice post describing the problem: http://www.russbishop.net/the-law
aforge pushed a commit to tinode/ios that referenced this pull request Oct 30, 2019
andriimakukha added a commit to mojio/SwiftWebSocket that referenced this pull request 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#tidwall#141
IanHoar/SwiftWebSocket PR#1
nosnilmot added a commit to nosnilmot/ndt7-client-ios that referenced this pull request Feb 14, 2023
Apply thread-safety fixes from
tidwall/SwiftWebSocket#141 to embedded copy of
SwiftWebSocket
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants