Skip to content

Commit ee9f0f7

Browse files
committed
SocketExceptions that are thrown during shut down of the socket should not bubble up.
Fixes PR #86.
1 parent f9773a6 commit ee9f0f7

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/Renci.SshNet/Channels/ChannelDirectTcpip.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ private void ShutdownSocket(SocketShutdown how)
132132
if (!_socket.IsConnected())
133133
return;
134134

135-
_socket.Shutdown(how);
135+
try
136+
{
137+
_socket.Shutdown(how);
138+
}
139+
catch (SocketException ex)
140+
{
141+
// TODO: log as warning
142+
DiagnosticAbstraction.Log("Failure shutting down socket: " + ex);
143+
}
136144
}
137145
}
138146

src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ internal class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip
2626
/// <param name="remoteChannelNumber">The remote channel number.</param>
2727
/// <param name="remoteWindowSize">The window size of the remote party.</param>
2828
/// <param name="remotePacketSize">The maximum size of a data packet that we can send to the remote party.</param>
29-
internal ChannelForwardedTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize)
30-
: base(session, localChannelNumber, localWindowSize, localPacketSize, remoteChannelNumber, remoteWindowSize, remotePacketSize)
29+
internal ChannelForwardedTcpip(ISession session,
30+
uint localChannelNumber,
31+
uint localWindowSize,
32+
uint localPacketSize,
33+
uint remoteChannelNumber,
34+
uint remoteWindowSize,
35+
uint remotePacketSize)
36+
: base(session,
37+
localChannelNumber,
38+
localWindowSize,
39+
localPacketSize,
40+
remoteChannelNumber,
41+
remoteWindowSize,
42+
remotePacketSize)
3143
{
3244
}
3345

@@ -116,7 +128,15 @@ private void ShutdownSocket(SocketShutdown how)
116128
if (!socket.IsConnected())
117129
return;
118130

119-
socket.Shutdown(how);
131+
try
132+
{
133+
socket.Shutdown(how);
134+
}
135+
catch (SocketException ex)
136+
{
137+
// TODO: log as warning
138+
DiagnosticAbstraction.Log("Failure shutting down socket: " + ex);
139+
}
120140
}
121141
}
122142

src/Renci.SshNet/Session.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,8 @@ private void SocketDisconnectAndDispose()
17961796
}
17971797
catch (SocketException ex)
17981798
{
1799-
// TODO: log as info or debug
1800-
DiagnosticAbstraction.Log("Failure shutting down socket or clearing read buffer: " + ex);
1799+
// TODO: log as warning
1800+
DiagnosticAbstraction.Log("Failure shutting down socket: " + ex);
18011801
}
18021802
}
18031803

0 commit comments

Comments
 (0)