Details
Description
I have a CentOS 6.4 system running httpd-2.4.9 on port 8000.
From this system, if I ssh to a MINA sshd-core 0.14.0 server running on Java SE 6 1.6.0_65-b14-466.1 using the following invocation
/usr/bin/ssh -R *:8000:localhost:8000 -p 2000 -N username@local-mina-server
I can reliably deadlock a remote forward channel after approximately five requests to localhost:8000 on the system running MINA.
After these requests I see one last line on the MINA server
2015-04-22 10:11:10,406 | TRACE | NioProcessor-3 | TcpipClientChannel | org.apache.sshd.client.channel.AbstractClientChannel 195 | Waiting for lock on channel TcpipClientChannel[id=9, recipient=0], mask=130, cond=0
and then I cease to be able to access the remotely forwarded port until after the MINA server has been restarted, even if I restart the client connection.
I believe the issue is related to this method in DefaultTcpipForwarder.java:
public void messageReceived(IoSession session, Readable message) throws Exception { TcpipClientChannel channel = (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class); Buffer buffer = new Buffer(); buffer.putBuffer(message); channel.waitFor(ClientChannel.OPENED | ClientChannel.CLOSED, Long.MAX_VALUE); channel.getInvertedIn().write(buffer.array(), buffer.rpos(), buffer.available()); channel.getInvertedIn().flush(); }
The channel lock wait request is given with a timeout of Long.MAX_VALUE, which seems unlikely to ever return in a synchronous environment like JRE 1.6.x. Initial testing indicates that a timeout of 5 seconds appears to fix the issue, but this may have unforeseen consequences that I haven't run into yet.
I cannot reproduce the issue on MINA SSHD 0.8.0, or when using JRE 1.7.x.