Skip to content

Commit

Permalink
Fix race condition causing unexpected idle disconnections
Browse files Browse the repository at this point in the history
This issue may appear when 'send[data]' methods are triggered from different threads. As a result
threads race appears between cancelIdleTimeoutExecutor and scheduling new idle task.
Example of race:
1. Thread 1 cancels task
2. Thread 2 waits until thread 1 will finish
3. Thread 1 finishes
4. Thread 2 tries to cancel already cancelled task and leaves synchronized block
5. Thread 1 schedules new idle task
6. Thread 2 schedules another idle task, the first is overwritten and never cancelled.
As a result disconnection is triggered precisely after set idle timeout passes.

Signed-off-by: Mykyta Leonov <[email protected]>
  • Loading branch information
Mykyta Leonov authored and jansupol committed Jul 18, 2023
1 parent f0e177e commit 0a1d33f
Showing 1 changed file with 1 addition and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ public void setHeartbeatInterval(long heartbeatInterval) {
}

void restartIdleTimeoutExecutor() {
cancelIdleTimeoutExecutor();

synchronized (idleTimeoutLock) {
cancelIdleTimeoutExecutor();
idleTimeoutFuture =
service.schedule(new IdleTimeoutCommand(), this.getMaxIdleTimeout(), TimeUnit.MILLISECONDS);
}
Expand Down

0 comments on commit 0a1d33f

Please sign in to comment.