From 5695b7d5f44e66b1b92d505d9138edd24eaaf204 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Tue, 2 Aug 2022 17:04:07 +0100 Subject: [PATCH] restore the interrupt flag whenever we catch InterruptedException --- src/main/java/net/schmizz/concurrent/Promise.java | 1 + src/main/java/net/schmizz/keepalive/KeepAlive.java | 2 ++ .../net/schmizz/sshj/connection/channel/ChannelInputStream.java | 1 + src/main/java/net/schmizz/sshj/connection/channel/Window.java | 1 + 4 files changed, 5 insertions(+) diff --git a/src/main/java/net/schmizz/concurrent/Promise.java b/src/main/java/net/schmizz/concurrent/Promise.java index 7511648d0..06b4a8353 100644 --- a/src/main/java/net/schmizz/concurrent/Promise.java +++ b/src/main/java/net/schmizz/concurrent/Promise.java @@ -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(); diff --git a/src/main/java/net/schmizz/keepalive/KeepAlive.java b/src/main/java/net/schmizz/keepalive/KeepAlive.java index 4ff892a05..05e771f73 100644 --- a/src/main/java/net/schmizz/keepalive/KeepAlive.java +++ b/src/main/java/net/schmizz/keepalive/KeepAlive.java @@ -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. diff --git a/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java b/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java index 85f0024d0..ee03d23cd 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java @@ -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); } } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/Window.java b/src/main/java/net/schmizz/sshj/connection/channel/Window.java index 8839f1e53..d20853e8b 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/Window.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/Window.java @@ -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); } }