[ https://issues.apache.org/jira/browse/SSHD-1289?focusedWorklogId=800119&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-800119 ]
ASF GitHub Bot logged work on SSHD-1289: ---------------------------------------- Author: ASF GitHub Bot Created on: 11/Aug/22 21:54 Start Date: 11/Aug/22 21:54 Worklog Time Spent: 10m Work Description: tomaswolf opened a new pull request, #238: URL: https://github.com/apache/mina-sshd/pull/238 Make sure that a thread does not try to acquire the write lock if it already holds the read lock. This could happen if a write is not enqueued and there is an exception during writing, and we then try to close the session on the same thread. The read/write lock is used for three purposes: first, it gives the flushing thread trying to empty the queue of pending packets priority over other threads trying to enqueue more packets, and second, it is held during writeOrEnqueue() while writing a packet directly to prevent that the KEX state changes between being checked and the write being done, and third, to prevent that the KEX state changes asynchronously while the flushing thread is checking it. The read/write lock itself does not serve to ensure mutual exclusion on the KEX state itself. These three functions can also be fulfilled if update() is executed when only the read lock is held. If a thread in update() holds the read lock, this can only occur if it wrote the buffer directly in writeOrEnqueue(), in which case it is fine to proceed, and the flushing thread for sure is not in its critical region where it holds the write lock. Otherwise, any other thread either is the flushing thread and holds the write lock already, or it's a thread not holding the lock at all. In both cases it is fine to acquire the write lock. Issue Time Tracking ------------------- Worklog Id: (was: 800119) Remaining Estimate: 0h Time Spent: 10m > Deadlock during session exit > ---------------------------- > > Key: SSHD-1289 > URL: https://issues.apache.org/jira/browse/SSHD-1289 > Project: MINA SSHD > Issue Type: Bug > Affects Versions: 2.9.0 > Reporter: Evgeny Pasynkov > Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > > {code} > java.lang.Thread.State: WAITING > at java.base@11.0.5/jdk.internal.misc.Unsafe.park(Native Method) > - waiting on > java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync@c50d1b2 > at > java.base@11.0.5/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194) > at > java.base@11.0.5/java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:885) > at > java.base@11.0.5/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:917) > at > java.base@11.0.5/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1240) > at > java.base@11.0.5/java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock.lock(ReentrantReadWriteLock.java:959) > at > org.apache.sshd.common.session.helpers.KeyExchangeMessageHandler.updateState(KeyExchangeMessageHandler.java:139) > at > org.apache.sshd.common.session.helpers.KeyExchangeMessageHandler.shutdown(KeyExchangeMessageHandler.java:186) > at > org.apache.sshd.common.session.helpers.AbstractSession.preClose(AbstractSession.java:967) > at > org.apache.sshd.common.util.closeable.AbstractCloseable.close(AbstractCloseable.java:94) > at > org.apache.sshd.common.session.helpers.AbstractSessionIoHandler.sessionClosed(AbstractSessionIoHandler.java:46) > at > org.apache.sshd.common.io.nio2.Nio2Session.doCloseImmediately(Nio2Session.java:283) > at > org.apache.sshd.common.util.closeable.AbstractCloseable.close(AbstractCloseable.java:95) > at > org.apache.sshd.common.io.nio2.Nio2Session.exceptionCaught(Nio2Session.java:215) > at > org.apache.sshd.common.io.nio2.Nio2Session.writeBuffer(Nio2Session.java:186) > at > org.apache.sshd.common.session.helpers.AbstractSession.doWritePacket(AbstractSession.java:1118) > - locked java.lang.Object@3423f353 > at > org.apache.sshd.common.session.helpers.KeyExchangeMessageHandler.writeOrEnqueue(KeyExchangeMessageHandler.java:285) > at > org.apache.sshd.common.session.helpers.KeyExchangeMessageHandler.writePacket(KeyExchangeMessageHandler.java:228) > at > org.apache.sshd.common.session.helpers.AbstractSession.writePacket(AbstractSession.java:1039) > at org.apache.sshd.common.session.Session.writePacket(Session.java:159) > at org.apache.sshd.common.session.Session.writePacket(Session.java:145) > at > org.apache.sshd.common.channel.AbstractChannel$GracefulChannelCloseable.close(AbstractChannel.java:637) > at > org.apache.sshd.common.util.closeable.SequentialCloseable$1.operationComplete(SequentialCloseable.java:56) > at > org.apache.sshd.common.util.closeable.SequentialCloseable$1.operationComplete(SequentialCloseable.java:45) > at > org.apache.sshd.common.util.closeable.SequentialCloseable.doClose(SequentialCloseable.java:69) > at > org.apache.sshd.common.util.closeable.SimpleCloseable.close(SimpleCloseable.java:63) > at > org.apache.sshd.common.util.closeable.SequentialCloseable$1.operationComplete(SequentialCloseable.java:56) > at > org.apache.sshd.common.util.closeable.SequentialCloseable$1.operationComplete(SequentialCloseable.java:45) > at > org.apache.sshd.common.future.AbstractSshFuture.lambda$notifyListener$2(AbstractSshFuture.java:162) > at > org.apache.sshd.common.future.AbstractSshFuture$$Lambda$352/0x0000000800890040.call(Unknown > Source) > at > org.apache.sshd.common.util.threads.ThreadUtils.runAsInternal(ThreadUtils.java:66) > at > org.apache.sshd.common.future.AbstractSshFuture.notifyListener(AbstractSshFuture.java:161) > at > org.apache.sshd.common.future.DefaultSshFuture.addListener(DefaultSshFuture.java:166) > at > org.apache.sshd.common.util.closeable.SequentialCloseable$1.operationComplete(SequentialCloseable.java:57) > at > org.apache.sshd.common.util.closeable.SequentialCloseable$1.operationComplete(SequentialCloseable.java:45) > at > org.apache.sshd.common.util.closeable.SequentialCloseable.doClose(SequentialCloseable.java:69) > at > org.apache.sshd.common.util.closeable.SimpleCloseable.close(SimpleCloseable.java:63) > at > org.apache.sshd.common.util.closeable.AbstractInnerCloseable.doCloseGracefully(AbstractInnerCloseable.java:41) > at > org.apache.sshd.common.util.closeable.AbstractCloseable.close(AbstractCloseable.java:110) > at > org.apache.sshd.server.channel.ChannelSession.closeShell(ChannelSession.java:916) > at > org.apache.sshd.server.channel.ChannelSession.lambda$prepareCommand$0(ChannelSession.java:779) > at > org.apache.sshd.server.channel.ChannelSession$$Lambda$414/0x00000008008fa440.onExit(Unknown > Source) > {code} > The lock is acquired in "KeyExchangeMessageHandler.writeOrEnqueue" and then > tries to re-acquire in "KeyExchangeMessageHandler.updateState" -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For additional commands, e-mail: dev-h...@mina.apache.org