[ 
https://issues.apache.org/jira/browse/SSHD-776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16191188#comment-16191188
 ] 

Fulvio Cavarretta commented on SSHD-776:
----------------------------------------

Hi [~lgoldstein], thanks for your advices.
Unfortunatelly the channel have been (corretly) close by Apache SSHD beacuse 
the remote FTP server have closed the socket (please follow  
_TcpipServerChannel[id=24, recipient=3]_ lifecycle )

_2017-10-04 10:10:34,599 DEBUG [4c75a]-nio2-thread-3] 
[Nio2Session.exceptionCaught] 
exceptionCaught(Nio2Session[local=/192.168.50.97:47262, 
remote=/192.168.10.31:41464]) caught IOException[Connection reset by peer] - 
calling handler_

Apache SSHD has not received {{SSH_MSG_CHANNEL_CLOSE}} confirmation message yet 
when it receives the {{SSH_MSG_CHANNEL_EOF}}, which I think it's perfectly 
legal, from the protocol point of view (https://www.ietf.org/rfc/rfc4254.txt 
par. _5.3.  Closing a Channel_), so probably 
_AbstractConnectionService.unregisterChannel_  should not called untill 
SSH_MSG_CHANNEL_CLOSE message is received.

We tried to fix/woraround the problem modifying the method 
_AbstractConnectionService.channelEof_ in a similar manner it has been done in 
_channelClose_ method, as following:

{code:java}
    public void channelEof(Buffer buffer) throws IOException {
        // Do not use getChannel to avoid the session being closed
        // if receiving the SSH_MSG_CHANNEL_EOF on an already closed channel
        int recipient = buffer.getInt();
        Channel channel = channels.get(recipient);
        if (channel != null) {
            channel.handleEof();
        } else {
            log.warn("Received {{SSH_MSG_CHANNEL_EOF}} on unknown channel " + 
recipient);
        }
    }
{code}

This workaround now seems to work, but we are anyway facing unexpected both 
session and transport loss in some cases, upon channel failure. The piece of 
offending code seems to be

_Nio2Session.doCloseImmediately_

{code}
    @Override
    protected void doCloseImmediately() {
        for (;;) {
             Nio2DefaultIoWriteFuture future = writes.poll();
*            if (future != null) {
                future.setException(new ClosedChannelException());
            } else {
                break;
            }
*        }

 ...
{code}


I'll keep you updated with our investigations with new traces when available.

Thanks a lot for your support.

P.S. We are do using local port forwarding mechanism of Apache SSHD!


> SSHD local port forwarding close session unexpectedly
> -----------------------------------------------------
>
>                 Key: SSHD-776
>                 URL: https://issues.apache.org/jira/browse/SSHD-776
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 1.6.0
>            Reporter: Fulvio Cavarretta
>            Assignee: Goldstein Lyor
>            Priority: Blocker
>         Attachments: dmzagent.trc, dmzagent.trc.2
>
>
> Apache SSHD used in local port forwarding mode.
> A client is connecting to a remote FTP server through Apache SSHD via a 
> custom software.
> When a new logical channel inside a single SSHD session get an IO error (e.g. 
> the remote destination close the connection suddenly, the whole session is 
> shut down causing all other logical channel to be closed (see line 8861of 
> attached trace file).
> It seems like the _exceptionCaught_ mathod should not be called in this case



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to