From 0a8673bf0c7ac59def39d13b195aa403a8e9b363 Mon Sep 17 00:00:00 2001 From: drieseng Date: Fri, 22 Jul 2016 20:12:42 +0200 Subject: [PATCH] Ignore ObjectDisposedException in AcceptAsync while stopping or stopped. --- ...rtLocalTest_Stop_PortStarted_ChannelBound.cs | 1 - src/Renci.SshNet/ForwardedPortDynamic.NET.cs | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs index 31761149..08819713 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs +++ b/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; diff --git a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs index 9f5f27cb..477e88d6 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs +++ b/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; } } }