Skip to content

Commit

Permalink
Fix cleanup race condition
Browse files Browse the repository at this point in the history
Fix race condition in Java due to timeout from no activity, misses the
cleaning deadline by a small number of milliseconds.

Fixes <Genymobile#154>

Evidence:

Selected keys size 1 now: 1562790544556 nextCleaningDeadline 1562790662669
Selected keys size 0 now: 1562790662667 nextCleaningDeadline 1562790662669
selector.select() returned without any event, an invalid SelectionKey was probably been registered
Selected keys size 0 now: 1562790662670 nextCleaningDeadline 1562790662669
Selected keys size 0 now: 1562790722672 nextCleaningDeadline 1562790722670
2019-07-10 16:32:02.673 I UDPConnection: UDP 10.0.0.2:31650 -> 208.67.222.222:53 Close

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
jstevenson authored and rom1v committed Sep 7, 2019
1 parent cfc63a2 commit c814bfb
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ public void run() throws IOException {
Set<SelectionKey> selectedKeys = selector.selectedKeys();

long now = System.currentTimeMillis();
if (now >= nextCleaningDeadline) {
if (now >= nextCleaningDeadline || selectedKeys.isEmpty()) {
tunnelServer.cleanUp();
nextCleaningDeadline = now + CLEANING_INTERVAL;
} else if (selectedKeys.isEmpty()) {
throw new AssertionError("selector.select() returned without any event, an invalid SelectionKey was probably been registered");
}

for (SelectionKey selectedKey : selectedKeys) {
Expand Down

0 comments on commit c814bfb

Please sign in to comment.