AspectUnk / russh-sftp

SFTP subsystem supported server and client for Russh
Apache License 2.0
64 stars 21 forks source link

Unable to Disconnect Using 'bye' Command #24

Closed yossyX closed 6 months ago

yossyX commented 7 months ago

Thank you for the wonderful library. However, I'm facing a critical issue.

When setting up an SFTP server using russh-sftp, clients connecting with the Linux sftp command are unable to disconnect using the bye command, leaving the terminal unresponsive.

When the bye command is executed, the server-side appears to exit the process_handler loop due to the Error::UnexpectedEof, but the connection is not closed, leaving both sides waiting for the other to disconnect.

I have confirmed this issue occurs with version 2.0.0-beta.4.

yossyX commented 7 months ago

I have resolved the issue. It seems that adding the following code would be helpful:

    async fn channel_eof(
        self,
        channel_id: ChannelId,
        mut session: Session,
    ) -> Result<(Self, Session), Self::Error> {
        session.close(channel_id);
        Ok((self, session))
    }
girstenbrei commented 6 months ago

Greets everyone, so I ran into this one as well: Can reproduce the problem as well as the fix. I tested this for both sftp (openssh-client @ 1:8.9p1-3ubuntu0.7) and paramiko(python3.10 & paramiko==3.4.0).

So, I've checked and this seems to be spec compliant: https://datatracker.ietf.org/doc/html/rfc4254#section-5.3:

Note that the channel remains open after this message, and more data may still be sent in the other direction.

So closing a channel after the EOF apparently needs to be a shared decision between client and server. I think for the basic server example, more people expect this behavior as mentioned by @yossyX , at least I did. I created #26 , let me know what you think!