Skip to content

System.ObjectDisposedException: Safe handle has been closed #1524

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

Closed
anandgmenon opened this issue Oct 23, 2024 · 1 comment · Fixed by #1531
Closed

System.ObjectDisposedException: Safe handle has been closed #1524

anandgmenon opened this issue Oct 23, 2024 · 1 comment · Fixed by #1531

Comments

@anandgmenon
Copy link

I am from the Azure Logic Apps team, we use the SSH.NET library in the SFTP connector there.

We have one user which runs into the following error Safe handle has been closed.. the usecase is the following:

The process runs every one minute and it tries to list a directory. We create a connection and try to maintain it. So every time before listing the directory we call sftpClient.IsConnected and if false we create a new connection.

The error happens Safe handle has been closed. after the there's a timeout on that connection is what we have observed.

Renci.SshNet.Common.SshOperationTimeoutException: Operation has timed out.
   at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, Int32 millisecondsTimeout)
   at Renci.SshNet.Sftp.SftpSession.RequestRealPath(String path, Boolean nullOnError)
   at Renci.SshNet.Sftp.SftpSession.GetCanonicalPath(String path)
   at Renci.SshNet.SftpClient.InternalListDirectory(String path, SftpListDirectoryAsyncResult asyncResult, Action`1 listCallback)

After which all the operation using that connection fails with the following exception, even though IsConnected returns true

System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
   at Interop.Kernel32.SetEvent(SafeWaitHandle handle)
   at System.Threading.EventWaitHandle.Set()
   at Renci.SshNet.Sftp.SftpSession.<>c__DisplayClass60_0.<RequestRealPath>b__0(SftpNameResponse response)
   at Renci.SshNet.Sftp.SftpSession.HandleResponse(SftpResponse response)
   at Renci.SshNet.Sftp.SftpSession.TryLoadSftpMessage(Byte[] packetData, Int32 offset, Int32 count)
--- End of stack trace from previous location ---
   at Renci.SshNet.Sftp.SftpSession.RequestRealPath(String path, Boolean nullOnError)
   at Renci.SshNet.Sftp.SftpSession.GetCanonicalPath(String path)
   at Renci.SshNet.SftpClient.InternalListDirectory(String path, SftpListDirectoryAsyncResult asyncResult, Action`1 listCallback)

Is this a bug? Is there any other reliable way to figure out if the connection is alive?

@Rob-Hague
Copy link
Collaborator

Sounds like #1519

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.

2 participants