sshnet / sshnet/SSH.NET

Unhandled Exception under Xamarin iOS

Open
#545 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

I'm using ssh.net in a Xamarin iOS application. When connecting to a sftp server with the iOS 's wifi turn off. I got this exception:
Unhandled Exception:
System.ObjectDisposedException: Safe handle has been closed occurred.
I debug the source code and found out that's because under Xamarin iOS
socket.ConnectAsync(args) return false when wifi is turned off.
SocketAbstraction.cs line 63 if (socket.ConnectAsync(args))
Then it run line 83 connectCompleted.Dispose();
At last function ConnectCompleted was called , where the exception occurred.

If I moved line 83 connectCompleted.Dispose() into below if statement like this:

       if (args.SocketError != SocketError.Success)
        {
            var socketError = (int) args.SocketError;

            // dispose Socket
            socket.Dispose();
            // dispose SocketAsyncEventArgs
            args.Dispose();

            // dispose ManualResetEvent
            connectCompleted.Dispose();

            throw new SocketException(socketError);
        }

then this bug is fixed.

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 SocketAbstraction.cs around line 63, where socket.ConnectAsync(args) is handled, and line 83, where connectCompleted is disposed. Reproduce the Xamarin iOS SFTP connection with Wi-Fi disabled and trace ConnectCompleted. Done means the failed connection raises the expected socket error without an ObjectDisposedException.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.