Skip to content

Commit d976706

Browse files
authored
Merge pull request #1080 from ably/ECO-5276/fix-deadlock-in-close
fix: deadlock in `WebSocket.close()`
2 parents 64575b8 + a75198a commit d976706

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/src/main/java/io/ably/lib/transport/WebSocketTransport.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ private synchronized void schedule(TimerTask task, long delay) {
381381
}
382382
}
383383

384-
private synchronized void onActivityTimerExpiry() {
385-
activityTimerTask = null;
384+
private void onActivityTimerExpiry() {
386385
long timeSinceLastActivity = System.currentTimeMillis() - lastActivityTime;
387386
long timeRemaining = getActivityTimeout() - timeSinceLastActivity;
388387

@@ -393,9 +392,12 @@ private synchronized void onActivityTimerExpiry() {
393392
return;
394393
}
395394

396-
// Otherwise, we've had some activity, restart the timer for the next timeout
397-
Log.v(TAG, "onActivityTimerExpiry: ok");
398-
startActivityTimer(timeRemaining + 100);
395+
synchronized (this) {
396+
activityTimerTask = null;
397+
// Otherwise, we've had some activity, restart the timer for the next timeout
398+
Log.v(TAG, "onActivityTimerExpiry: ok");
399+
startActivityTimer(timeRemaining + 100);
400+
}
399401
}
400402

401403
private long getActivityTimeout() {

0 commit comments

Comments
 (0)