mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix - ReconnectingWebSocket race condition mClosed
Summary: Changelog : [Internal] Use synchronized blocks to avoid race conditions surrounding mClosed. Reviewed By: makovkastar Differential Revision: D31019994 fbshipit-source-id: 48793bd3bea98224d8df344bc4fc8771b517cf72
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e20335a2ac
commit
94bcfb71a2
+12
-6
@@ -66,8 +66,10 @@ public final class ReconnectingWebSocket extends WebSocketListener {
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (mClosed) {
|
||||
throw new IllegalStateException("Can't connect closed client");
|
||||
synchronized (this) {
|
||||
if (mClosed) {
|
||||
throw new IllegalStateException("Can't connect closed client");
|
||||
}
|
||||
}
|
||||
|
||||
Request request = new Request.Builder().url(mUrl).build();
|
||||
@@ -82,8 +84,10 @@ public final class ReconnectingWebSocket extends WebSocketListener {
|
||||
}
|
||||
|
||||
private void reconnect() {
|
||||
if (mClosed) {
|
||||
throw new IllegalStateException("Can't reconnect closed client");
|
||||
synchronized (this) {
|
||||
if (mClosed) {
|
||||
throw new IllegalStateException("Can't reconnect closed client");
|
||||
}
|
||||
}
|
||||
|
||||
if (!mSuppressConnectionErrors) {
|
||||
@@ -102,8 +106,10 @@ public final class ReconnectingWebSocket extends WebSocketListener {
|
||||
}
|
||||
|
||||
public void closeQuietly() {
|
||||
mClosed = true;
|
||||
closeWebSocketQuietly();
|
||||
synchronized (this) {
|
||||
mClosed = true;
|
||||
closeWebSocketQuietly();
|
||||
}
|
||||
mMessageCallback = null;
|
||||
|
||||
if (mConnectionCallback != null) {
|
||||
|
||||
Reference in New Issue
Block a user