Skip to content

Commit 94bcfb7

Browse files
amy588facebook-github-bot
authored andcommitted
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
1 parent e20335a commit 94bcfb7

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

ReactAndroid/src/main/java/com/facebook/react/packagerconnection/ReconnectingWebSocket.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ public ReconnectingWebSocket(
6666
}
6767

6868
public void connect() {
69-
if (mClosed) {
70-
throw new IllegalStateException("Can't connect closed client");
69+
synchronized (this) {
70+
if (mClosed) {
71+
throw new IllegalStateException("Can't connect closed client");
72+
}
7173
}
7274

7375
Request request = new Request.Builder().url(mUrl).build();
@@ -82,8 +84,10 @@ private synchronized void delayedReconnect() {
8284
}
8385

8486
private void reconnect() {
85-
if (mClosed) {
86-
throw new IllegalStateException("Can't reconnect closed client");
87+
synchronized (this) {
88+
if (mClosed) {
89+
throw new IllegalStateException("Can't reconnect closed client");
90+
}
8791
}
8892

8993
if (!mSuppressConnectionErrors) {
@@ -102,8 +106,10 @@ public void run() {
102106
}
103107

104108
public void closeQuietly() {
105-
mClosed = true;
106-
closeWebSocketQuietly();
109+
synchronized (this) {
110+
mClosed = true;
111+
closeWebSocketQuietly();
112+
}
107113
mMessageCallback = null;
108114

109115
if (mConnectionCallback != null) {

0 commit comments

Comments
 (0)