Skip to content

Commit

Permalink
Fix race condition in Java due to timeout from no activity, misses th…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
jstevenson committed Jul 10, 2019
1 parent 2bf8a3c commit f5dd2fc
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 f5dd2fc

Please sign in to comment.