-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TCP connection leakage issue when using the remote port forwarding feature #663
Comments
Thanks for reporting this. This race condition is ugly and, other than I had expected, not specific to this TCP/IP forwarding. The TcpipServerChannel does everything correctly. It connects to port B, and if the channel or session is closed, it also closes the The problem is in the IoSessions are created and registered in the IoConnector, and when the IoConnector is closed, it also closes all registered sessions. But IoSessions are created asynchronously, and so it is possible that an IoSession is registered after the IoConnector has already been closed. When that happens, we end up with an IoSession that will probably remain around forever. |
So, in what way should I fix that issue? |
Here is my additional information regarding this issue. There are two types of NettyIoSession objects here. The first type is for the connection established when the client connects to the server, and the second type is for the connection when the client connects to the local port (8001). When the connection between the client and the server times out, the ClientSessionImpl will be closed. During this period, if the "SSH_MSG_CHANNEL_OPEN" event is received and even after the ClientSessionImpl has been closed, a TCP connection from the client to the local port (8001) will still be established. |
I'm preparing a fix, for all three transports. |
Version
2.10.0
Bug description
When utilizing the remote port forwarding functionality, I've noticed that TCP connections are not being properly closed between the SSH client process and the local port on the SSH client side.The issue occurs intermittently when the machine's resources are under significant strain, and currently, I can only reproduce it using the IntelliJ IDEA debug functionality.
As depicted in the attached image, these connections fail to close correctly between the SSH client and "near" component.
Steps to Reproduce
client code
server code
Navigate to the org.apache.sshd.server.forward.TcpipServerChannel#handleChannelConnectResult method and set a breakpoint on the line ”if (future.isConnected())“.
The server initiates asynchronous and periodic connections to port A. Subsequently, the client will automatically connect to port 8001 to establish a connection. During this process, the code execution will pause at the breakpoint set in the TcpipServerChannel#handleChannelConnectResult method.
It is recommended that you wait for a while, perhaps a few minutes.After that, resume the code execution from the breakpoint.At this point, the session will actually be closed. Logically, all connections to port 8001 should also be terminated.
However, when you execute the ss command on the client machine with the following filter: ss -lanp |grep 8001 |grep ES |grep java, you will notice that some connections remain open and have not been properly closed.
Actual behavior
Under resource - constrained conditions and when using IntelliJ IDEA's debug mode, connections between the SSH client and the "near" component do not close as expected, resulting in resource leakage and potential system instability.
Expected behavior
Regardless of the system's resource state, once the SSH client connections are closed or the relevant operations are completed, all connections between the SSH client and the "near" component should be properly terminated, and system resources should be released.
Relevant log output
Other information
No response
The text was updated successfully, but these errors were encountered: