Jiachen Lu created SSHD-1341: -------------------------------- Summary: Deadlock in old version of SSHD Key: SSHD-1341 URL: https://issues.apache.org/jira/browse/SSHD-1341 Project: MINA SSHD Issue Type: Question Affects Versions: 0.14.0 Reporter: Jiachen Lu Attachments: image-2024-06-16-21-16-19-706.png, image-2024-06-16-21-16-41-229.png
# SSHD Deadlock ## In a nutshell I used some static analysis tools to discover a potential deadlock in version 0.14.x of mina-sshd. I would like to know if it is a false positive. The related lock objects and trace are shown below. I look forward to the community's assistance in confirming this issue. Thank you for your response. If you need more information, please feel free to contact me. This deadlock might be similar to [SSHD-966](https://issues.apache.org/jira/browse/SSHD-966). ## Deadlock Pair Deadlock `synchronized void flush() throws IOException` (Trace 1) and `synchronized (encodeLock)` (Trace 2) acquire locks `this` in class `ChannelOutputStream` and `encodeLock` in reverse orders. ./sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java ```java 551 protected IoWriteFuture doWritePacket(Buffer buffer) throws IOException { 552 // Synchronize all write requests as needed by the encoding algorithm 553 // and also queue the write request in this synchronized block to ensure 554 // packets are sent in the correct order 555 > synchronized (encodeLock) { 556 encode(buffer); 557 return ioSession.write(buffer); 558 } 559 } ``` Deadlock `synchronized void flush() throws IOException` (Trace 1) and `synchronized (encodeLock)` (Trace 2) acquire locks `this` in class `ChannelOutputStream` and `encodeLock` in reverse orders. ./sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java ```java 113 public void messageReceived(IoSession session, Readable message) throws Exception { 114 if (isClosing()) { 115 log.debug("Ignoring write to channel {} in CLOSING state", id); 116 } else { 117 Buffer buffer = new Buffer(); 118 buffer.putBuffer(message); 119 out.write(buffer.array(), buffer.rpos(), buffer.available()); 120 > out.flush(); 121 } 122 } ``` ## Trace ### Trace1 !image-2024-06-16-21-16-19-706.png! ### Trace2 !image-2024-06-16-21-16-41-229.png! -- 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