sshnet / sshnet/SSH.NET

ObjectDisposedException once in a while

Open
#560 0 comments 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

https://github.com/sshnet/SSH.NET/blob/7691cb0b55f5e0de8dc2ad48dd824419471ab710/src/Renci.SshNet/ForwardedPortLocal.NET.cs#L63

We are seeing ObjectDisposedExceptions once in a while:

Frameworkversion: v4.0.30319
Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet.
Ausnahmeinformationen: System.ObjectDisposedException
bei System.Net.Sockets.Socket.AcceptAsync(System.Net.Sockets.SocketAsyncEventArgs)
bei Renci.SshNet.ForwardedPortLocal.StartAccept(System.Net.Sockets.SocketAsyncEventArgs)
bei Renci.SshNet.ForwardedPortLocal.AcceptCompleted(System.Object, System.Net.Sockets.SocketAsyncEventArgs)
bei System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs)
bei System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
bei System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(System.Net.Sockets.SocketError, Int32, System.Net.Sockets.SocketFlags)
bei System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
bei System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

These exceptions should be prevented in SSH.Net by catching the exception and ignoring it if the status is Stopped or Stopping. The status is set to Stopping before the _listener is disposed.
However, the status is checked for Stopped twice, instead of Stopping or Stopped. This is a simple oversight.

Same thing in ForwardedPortDynamic.NET.cs

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/ForwardedPortLocal.NET.cs at StartAccept and inspect the status check around listener disposal, then compare the corresponding logic in ForwardedPortDynamic.NET.cs. Reproduce or reason through an accept completion during shutdown; done means shutdown-time ObjectDisposedException instances are prevented in both forwarded-port implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.