Skip to content

Commit 65bd072

Browse files
committed
Stop listener before waiting for channels to close.
Remove extra exception handling.
1 parent 32becde commit 65bd072

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

src/Renci.SshNet/ForwardedPortLocal.NET.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,7 @@ partial void InternalStart()
3232
// consider port started when we're listening for inbound connections
3333
_status = ForwardedPortStatus.Started;
3434

35-
try
36-
{
37-
StartAccept(null);
38-
}
39-
catch (ObjectDisposedException)
40-
{
41-
// AcceptAsync will throw an ObjectDisposedException when the server is closed before
42-
// the listener has started accepting connections.
43-
//
44-
// this is only possible when the listener is stopped (from another thread) right
45-
// after it was started.
46-
StopPort(Session.ConnectionInfo.Timeout);
47-
}
48-
catch (Exception ex)
49-
{
50-
StopPort(Session.ConnectionInfo.Timeout);
51-
RaiseExceptionEvent(ex);
52-
}
35+
StartAccept(null);
5336
}
5437

5538
private void StartAccept(SocketAsyncEventArgs e)

src/Renci.SshNet/ForwardedPortLocal.cs

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

132132
// signal existing channels that the port is closing
133133
base.StopPort(timeout);
134+
// prevent new requests from getting processed
135+
StopListener();
134136
// wait for open channels to close
135137
InternalStop(timeout);
136-
// prevent new requests from getting processed before we signal existing
137-
// channels that the port is closing
138-
StopListener();
139138
// mark port stopped
140139
_status = ForwardedPortStatus.Stopped;
141140
}

0 commit comments

Comments
 (0)