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;
this.asyncIn = asyncIn;
}
+ @GuardedBy("asyncInLock")
+ private boolean isWriteExecuted = false;
+
public void write(final ChannelHandlerContext ctx,
final Object msg, final ChannelPromise promise) {
if (asyncIn == null) {
promise.setFailure(new IllegalStateException("Channel closed"));
} else {
final ByteBuf byteBufMsg = (ByteBuf) msg;
- if (!pending.isEmpty()) {
+ if (isWriteExecuted) {
queueRequest(ctx, byteBufMsg, promise);
return;
}
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
private void writePendingIfAny() {
synchronized (asyncInLock) {
if (pending.peek() == null) {
+ isWriteExecuted = false;
return;
}