Răsfoiți Sursa

Ignore ObjectDisposedException in AcceptAsync while stopping or stopped.

drieseng 9 ani în urmă
părinte
comite
0a8673bf0c

+ 0 - 1
src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;

+ 15 - 2
src/Renci.SshNet/ForwardedPortDynamic.NET.cs

@@ -79,9 +79,22 @@ namespace Renci.SshNet
             // only accept new connections while we are started
             if (IsStarted)
             {
-                if (!_listener.AcceptAsync(e))
+                try
                 {
-                    AcceptCompleted(null, e);
+                    if (!_listener.AcceptAsync(e))
+                    {
+                        AcceptCompleted(null, e);
+                    }
+                }
+                catch (ObjectDisposedException)
+                {
+                    if (_status == ForwardedPortStatus.Stopped || _status == ForwardedPortStatus.Stopped)
+                    {
+                        // ignore ObjectDisposedException while stopping or stopped
+                        return;
+                    }
+
+                    throw;
                 }
             }
         }