2. SSHD-151

Direct TCP/IP Port Forward sends EOF to client after closing channel


    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.6.0
    • Fix Version/s: 0.7.0
    • Labels:


      While testing port forwarding from an OpenSSH_5.8p2 client to a MINA SSHD server, I noticed that after the first disconnection of a client from the forwarded port, the entire SSH session would be disconnected. The client command I ran was:

      ssh -N -L 60443:<target>:443 -p 50022 tester@<minasshd>

      Looking at the traces, I saw the following from SSHD:

      13:54:12.823 [NioProcessor-1] DEBUG o.a.s.server.session.ServerSession - Received packet SSH_MSG_CHANNEL_OPEN
      13:54:12.823 [NioProcessor-1] INFO o.a.s.server.session.ServerSession - Received SSH_MSG_CHANNEL_OPEN direct-tcpip
      13:54:12.826 [NioProcessor-1] INFO o.a.s.s.channel.ChannelDirectTcpip - Receiving request for direct tcpip: hostToConnect=<target>, portToConnect=443, originatorIpAddress=, originatorPort=54145
      13:54:15.588 [NioProcessor-1] DEBUG o.a.s.server.session.ServerSession - Received packet SSH_MSG_CHANNEL_EOF
      13:54:15.589 [NioProcessor-1] INFO o.a.s.s.channel.ChannelDirectTcpip - Received SSH_MSG_CHANNEL_EOF on channel 0
      13:54:15.589 [NioProcessor-1] INFO o.a.s.s.channel.ChannelDirectTcpip - Send SSH_MSG_CHANNEL_CLOSE on channel 0
      13:54:15.590 [NioProcessor-1] DEBUG o.a.s.server.session.ServerSession - Received packet SSH_MSG_CHANNEL_CLOSE
      13:54:15.590 [NioProcessor-1] INFO o.a.s.s.channel.ChannelDirectTcpip - Received SSH_MSG_CHANNEL_CLOSE on channel 0
      13:54:15.590 [NioProcessor-1] INFO o.a.s.s.channel.ChannelDirectTcpip - Closing channel 0 immediately
      13:54:15.591 [NioProcessor-1] INFO o.a.s.s.channel.ChannelDirectTcpip - Closing channel 0 immediately
      13:54:15.593 [NioProcessor-26] INFO o.a.s.s.channel.ChannelDirectTcpip - Send SSH_MSG_CHANNEL_EOF on channel 0
      13:54:15.595 [NioProcessor-1] DEBUG o.a.s.server.session.ServerSession - Received packet SSH_MSG_DISCONNECT
      13:54:15.595 [NioProcessor-1] INFO o.a.s.server.session.ServerSession - Received SSH_MSG_DISCONNECT (reason=2, msg=Received ieof for nonexistent channel 2.)
      13:54:15.595 [NioProcessor-1] INFO o.a.s.server.session.ServerSession - Closing session
      13:54:15.595 [NioProcessor-1] DEBUG o.a.s.server.session.ServerSession - Closing IoSession
      13:54:15.596 [NioProcessor-1] DEBUG o.a.s.server.session.ServerSession - IoSession closed

      So if I read this right, the client sends an EOF, then the server sends a CLOSE, then the client sends a CLOSE. After all of this, the server sends back an EOF, but the channel no longer exists at the client, which causes a disconnection.

      I looked into the source code, and figured the following change might correct the issue:

      Index: sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDirectTcpip.java
      — sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDirectTcpip.java (revision 1207930)
      +++ sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDirectTcpip.java (working copy)
      @@ -109,7 +109,9 @@

      public void sessionClosed(IoSession session) throws Exception {
      + if (!closing)

      { sendEof(); + }


      It appears to work, but I do not know if it is correct, or if it will break other situations. Can anyone comment on it?

        Issue Links


          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          172d 21h 15m 1 Guillaume Nodet 21/May/12 15:42
          Andrew C made changes -
          Link This issue is cloned as SSHD-207 [ SSHD-207 ]
          Andrew C made changes -
          Link This issue relates to SSHD-206 [ SSHD-206 ]
          Guillaume Nodet made changes -
          Field Original Value New Value
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Guillaume Nodet [ gnt ]
          Fix Version/s 0.7.0 [ 12317953 ]
          Resolution Fixed [ 1 ]
          Guillaume Nodet added a comment -

          Thx the patch Kevin.

          Guillaume Nodet added a comment - Thx the patch Kevin.
          Kevin Winchester created issue -


            • Assignee:
              Guillaume Nodet
              Kevin Winchester
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: