Skip to content

Commit

Permalink
restore the interrupt flag whenever we catch InterruptedException
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Heneveld committed Aug 2, 2022
1 parent 5674072 commit 5695b7d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/schmizz/concurrent/Promise.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public V tryRetrieve(long timeout, TimeUnit unit)
}
return val;
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw chainer.chain(ie);
} finally {
lock.unlock();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/schmizz/keepalive/KeepAlive.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void run() {
TimeUnit.SECONDS.sleep(interval);
}
} catch (InterruptedException e) {
// this is almost certainly a planned interruption, but even so, no harm in setting the interrupt flag
Thread.currentThread().interrupt();
log.trace("{} Interrupted while sleeping", getClass().getSimpleName());
} catch (Exception e) {
// If we weren't interrupted, kill the transport, then this exception was unexpected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public int read(byte[] b, int off, int len)
try {
buf.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw (IOException) new InterruptedIOException().initCause(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public long awaitExpansion(long was) throws ConnectionException {
throw new ConnectionException("Timeout when trying to expand the window size");
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new ConnectionException(ie);
}
}
Expand Down

0 comments on commit 5695b7d

Please sign in to comment.