sshnet / sshnet/SSH.NET

ObjectDisposedException while connecting ssh

Open
#584 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

sometimes I get an error while using ssh connection, it is the cause of crashed app, with the following log messages:

2019-09-16 10:04:22.710 OneLink.iOS[307:17928]
Unhandled Exception:
System.ObjectDisposedException: Safe handle has been closed
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef (System.Boolean& success) [0x0001c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/corlib/System.Runtime.InteropServices/SafeHandle.cs:125
at System.Threading.NativeEventCalls.SetEvent (Microsoft.Win32.SafeHandles.SafeWaitHandle handle) [0x00002] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/corlib/System.Threading/NativeEventCalls.cs:61
at System.Threading.EventWaitHandle.Set () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/eventwaithandle.cs:319
at Renci.SshNet.Abstractions.SocketAbstraction.ConnectCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x0000f] in :0

==========================================
I checked your codes, and I think that the problem in the function
public static Socket Connect(IPEndPoint remoteEndpoint, TimeSpan connectTimeout)
in file src/Renci.SshNet/Abstractions/SocketAbstraction.cs.
Maybe we must remove Completed callback function before disposing of ManualResetEvent.

Can you help me to check this issue?

Thanks so much!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Renci.SshNet/Abstractions/SocketAbstraction.cs at Connect(IPEndPoint remoteEndpoint, TimeSpan connectTimeout). Trace the SocketAsyncEventArgs.Completed callback and the ManualResetEvent lifetime around timeout and disposal. Done means the reported ObjectDisposedException no longer occurs while connecting over SSH, including when the connection completes near disposal.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.