Skip to content

Commit 5498b8f

Browse files
committed
Remove extra exception handling.
Stop listener first, before we wait for open channels to close.
1 parent 44c21ca commit 5498b8f

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

src/Renci.SshNet/ForwardedPortDynamic.NET.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public partial class ForwardedPortDynamic
1717

1818
partial void InternalStart()
1919
{
20+
InitializePendingChannelCountdown();
21+
2022
var ip = IPAddress.Any;
2123
if (!string.IsNullOrEmpty(BoundHost))
2224
{
@@ -32,29 +34,10 @@ partial void InternalStart()
3234
Session.ErrorOccured += Session_ErrorOccured;
3335
Session.Disconnected += Session_Disconnected;
3436

35-
InitializePendingChannelCountdown();
37+
StartAccept(null);
3638

3739
// consider port started when we're listening for inbound connections
3840
_status = ForwardedPortStatus.Started;
39-
40-
try
41-
{
42-
StartAccept(null);
43-
}
44-
catch (ObjectDisposedException)
45-
{
46-
// AcceptAsync will throw an ObjectDisposedException when the server is closed before
47-
// the listener has started accepting connections.
48-
//
49-
// this is only possible when the listener is stopped (from another thread) right
50-
// after it was started.
51-
StopPort(Session.ConnectionInfo.Timeout);
52-
}
53-
catch (Exception ex)
54-
{
55-
StopPort(Session.ConnectionInfo.Timeout);
56-
RaiseExceptionEvent(ex);
57-
}
5841
}
5942

6043
private void StartAccept(SocketAsyncEventArgs e)

src/Renci.SshNet/ForwardedPortDynamic.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ protected override void StopPort(TimeSpan timeout)
8282

8383
// signal existing channels that the port is closing
8484
base.StopPort(timeout);
85+
// prevent new requests from getting processed
86+
StopListener();
8587
// wait for open channels to close
8688
InternalStop(timeout);
87-
// prevent new requests from getting processed before we signal existing
88-
// channels that the port is closing
89-
StopListener();
9089
// mark port stopped
9190
_status = ForwardedPortStatus.Stopped;
9291
}

0 commit comments

Comments
 (0)