From: Jaroslav Tóth Date: Tue, 2 Apr 2019 03:41:32 +0000 (+0200) Subject: Fixed deadlock in AsyncSshHandlerWriter X-Git-Tag: release/neon-sr1~4 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=c59a0370adf5660009a8352e31c017ad4274039a Fixed deadlock in AsyncSshHandlerWriter Deadlock happened when listener for window is resized and write is invoked at the same time. Change-Id: I8c662d6cd5edbc3e36b31a754d826f79bec76434 Signed-off-by: Martin Sunal Signed-off-by: Jaroslav Tóth (cherry picked from commit 0f45153d60a0fc71a08d011e21fdf5e83c174290) --- diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java index f35372742e..e05408551f 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java @@ -21,6 +21,7 @@ import org.apache.sshd.common.io.IoOutputStream; import org.apache.sshd.common.io.WritePendingException; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.buffer.ByteArrayBuffer; +import org.checkerframework.checker.lock.qual.GuardedBy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +51,9 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { this.asyncIn = asyncIn; } + @GuardedBy("asyncInLock") + private boolean isWriteExecuted = false; + public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { if (asyncIn == null) { @@ -67,7 +71,7 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { promise.setFailure(new IllegalStateException("Channel closed")); } else { final ByteBuf byteBufMsg = (ByteBuf) msg; - if (!pending.isEmpty()) { + if (isWriteExecuted) { queueRequest(ctx, byteBufMsg, promise); return; } @@ -86,6 +90,9 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { if (LOG.isTraceEnabled()) { LOG.trace("Writing request on channel: {}, message: {}", ctx.channel(), byteBufToString(byteBufMsg)); } + + isWriteExecuted = true; + asyncIn.writePacket(toBuffer(byteBufMsg)).addListener(future -> { // synchronized block due to deadlock that happens on ssh window resize // writes and pending writes would lock the underlyinch channel session @@ -133,6 +140,7 @@ public final class AsyncSshHandlerWriter implements AutoCloseable { private void writePendingIfAny() { synchronized (asyncInLock) { if (pending.peek() == null) { + isWriteExecuted = false; return; }