Commit 81682fe
committed
IXWebSocketTransport::setReadyState(): Run under lock
When setReadyState(CLOSED) is executed from two different threads (the
server's thread, detecting a close trying to receive and a separate
sending thread), there is a race where both see _readyState as non-CLOSED
and both execute the _onCloseCallback(). Worse, the server's thread might
be returning from ->run(), unsetting the callback while the other thread
is still about to call the _onCloseCallback(), resulting in a crash
rather than "just" a duplicate invocation of the callback.
This change ensures that setReadyState() *and* the_onCloseCallback()
are executed by a single thread till completion, by taking a new mutex
that's used to synchronize access to _readyState.
I've first tried _readyState.exchange() which seemed promising, but still
crashed once in a while as racing threads do not wait for the
_onCloseCallback() to complete.1 parent 8115594 commit 81682fe
2 files changed
+6
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
| 209 | + | |
| 210 | + | |
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
188 | 190 | | |
189 | 191 | | |
190 | 192 | | |
| |||
0 commit comments