From 21c5c8e0b42153314ef8a8e009f9352d4a89e67b Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 5 Apr 2020 11:34:36 +0200 Subject: [PATCH] Log warning upon timeout waiting for pending channels to reach zero. --- src/Renci.SshNet/ForwardedPortDynamic.NET.cs | 7 ++++++- src/Renci.SshNet/ForwardedPortLocal.NET.cs | 6 +++++- src/Renci.SshNet/ForwardedPortRemote.cs | 12 +++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs index b2c16cd2..36a80455 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs +++ b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs @@ -264,7 +264,12 @@ namespace Renci.SshNet partial void InternalStop(TimeSpan timeout) { _pendingChannelCountdown.Signal(); - _pendingChannelCountdown.Wait(timeout); + if (!_pendingChannelCountdown.Wait(timeout)) + { + // TODO: log as warning + DiagnosticAbstraction.Log("Timeout waiting for pending channels in dynamic forwarded port to close."); + } + } partial void InternalDispose(bool disposing) diff --git a/src/Renci.SshNet/ForwardedPortLocal.NET.cs b/src/Renci.SshNet/ForwardedPortLocal.NET.cs index ed8f89c0..ba01ddbd 100644 --- a/src/Renci.SshNet/ForwardedPortLocal.NET.cs +++ b/src/Renci.SshNet/ForwardedPortLocal.NET.cs @@ -214,7 +214,11 @@ namespace Renci.SshNet partial void InternalStop(TimeSpan timeout) { _pendingChannelCountdown.Signal(); - _pendingChannelCountdown.Wait(timeout); + if (!_pendingChannelCountdown.Wait(timeout)) + { + // TODO: log as warning + DiagnosticAbstraction.Log("Timeout waiting for pending channels in local forwarded port to close."); + } } partial void InternalDispose(bool disposing) diff --git a/src/Renci.SshNet/ForwardedPortRemote.cs b/src/Renci.SshNet/ForwardedPortRemote.cs index 4b5915de..b2ed15fe 100644 --- a/src/Renci.SshNet/ForwardedPortRemote.cs +++ b/src/Renci.SshNet/ForwardedPortRemote.cs @@ -201,7 +201,12 @@ namespace Renci.SshNet // wait for pending channels to close _pendingChannelCountdown.Signal(); - _pendingChannelCountdown.Wait(timeout); + + if (!_pendingChannelCountdown.Wait(timeout)) + { + // TODO: log as warning + DiagnosticAbstraction.Log("Timeout waiting for pending channels in remote forwarded port to close."); + } _status = ForwardedPortStatus.Stopped; } @@ -244,10 +249,7 @@ namespace Renci.SshNet { RaiseRequestReceived(info.OriginatorAddress, info.OriginatorPort); - using ( - var channel = - Session.CreateChannelForwardedTcpip(channelOpenMessage.LocalChannelNumber, - channelOpenMessage.InitialWindowSize, channelOpenMessage.MaximumPacketSize)) + using (var channel = Session.CreateChannelForwardedTcpip(channelOpenMessage.LocalChannelNumber, channelOpenMessage.InitialWindowSize, channelOpenMessage.MaximumPacketSize)) { channel.Exception += Channel_Exception; channel.Bind(new IPEndPoint(HostAddress, (int) Port), this);