Skip to content

Commit

Permalink
Fix - ReconnectingWebSocket race condition mClosed
Browse files Browse the repository at this point in the history
Summary:
Changelog : [Internal]
Use synchronized blocks to avoid race conditions surrounding mClosed.

Reviewed By: makovkastar

Differential Revision: D31019994

fbshipit-source-id: 48793bd3bea98224d8df344bc4fc8771b517cf72
  • Loading branch information
amy588 authored and facebook-github-bot committed Sep 22, 2021
1 parent e20335a commit 94bcfb7
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public ReconnectingWebSocket(
}

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();
Expand All @@ -82,8 +84,10 @@ private synchronized void delayedReconnect() {
}

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) {
Expand All @@ -102,8 +106,10 @@ public void run() {
}

public void closeQuietly() {
mClosed = true;
closeWebSocketQuietly();
synchronized (this) {
mClosed = true;
closeWebSocketQuietly();
}
mMessageCallback = null;

if (mConnectionCallback != null) {
Expand Down

0 comments on commit 94bcfb7

Please sign in to comment.