Skip to content
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

SftpClient.IsConnect returns true even if session is closed. #1153

Closed
anandgmenon opened this issue Jul 24, 2023 · 0 comments · Fixed by #1362
Closed

SftpClient.IsConnect returns true even if session is closed. #1153

anandgmenon opened this issue Jul 24, 2023 · 0 comments · Fixed by #1362

Comments

@anandgmenon
Copy link

This is similar to the discussion in #843

We have a connection pool implemented for the SftpClient and we reconnect whenever SftpClient.IsConnected() returns false.
However we have noticed issues where SftpClient.IsConnected() still returns true in case the server has closed the session and we eventually get the following error when using the client for any operation

System.InvalidOperationException: The session is not open. at Renci.SshNet.Common.AsyncResult.EndInvoke() at Renci.SshNet.SftpClient.EndListDirectory(IAsyncResult asyncResult)

Is this an expected behaviour? If not, can we try to implement the fix mentioned #843 or expose a method to determine if the session is open or not?

mus65 added a commit to mus65/SSH.NET that referenced this issue Mar 23, 2024
If the server closes the SFTP session but keeps the TCP connection open,
this currently causes IsConnected to return true, but any operation
fails with "the session is not open".

SftpClient.IsConnected now also check sftpSession.IsOpen. Connect()
and ConnectAsync() were reworked to take into account that the Session
may already/still be open, but the SFTP session may not. This is needed
so a reconnect works.

fixes sshnet#843 and sshnet#1153
WojciechNagorski pushed a commit that referenced this issue Apr 4, 2024
* SftpClient: handle the SFTP session being closed by the server

If the server closes the SFTP session but keeps the TCP connection open,
this currently causes IsConnected to return true, but any operation
fails with "the session is not open".

SftpClient.IsConnected now also check sftpSession.IsOpen. Connect()
and ConnectAsync() were reworked to take into account that the Session
may already/still be open, but the SFTP session may not. This is needed
so a reconnect works.

fixes #843 and #1153

* Always re-create session

---------

Co-authored-by: Rob Hague <[email protected]>
Co-authored-by: Igor Milavec <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant