Skip to content

Commit b413970

Browse files
committed
Added more tracing, and break receive loop when we start disconnecting.
1 parent 4632a33 commit b413970

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Renci.SshNet/Session.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,8 @@ private void SocketDisconnectAndDispose()
18661866
{
18671867
try
18681868
{
1869+
DiagnosticAbstraction.Log(string.Format("[{0}] Shutting down socket.", ToHex(SessionId)));
1870+
18691871
// interrupt any pending reads; should be done outside of socket read lock as we
18701872
// actually want shutdown the socket to make sure blocking reads are interrupted
18711873
//
@@ -1891,13 +1893,26 @@ private void SocketDisconnectAndDispose()
18911893
}
18921894
#endif // FEATURE_SOCKET_POLL
18931895
}
1896+
catch (SshOperationTimeoutException ex)
1897+
{
1898+
// TODO: log as info or debug
1899+
DiagnosticAbstraction.Log("Time-out shutting down socket or clearing read buffer: " + ex);
1900+
}
18941901
catch (SocketException ex)
18951902
{
1903+
// TODO: log as info or debug
18961904
DiagnosticAbstraction.Log("Failure shutting down socket or clearing read buffer: " + ex);
18971905
}
1906+
catch (Exception ex)
1907+
{
1908+
// TODO: log as warning
1909+
DiagnosticAbstraction.Log("Time-out shutting down socket or clearing read buffer: " + ex);
1910+
}
18981911
}
18991912

1913+
DiagnosticAbstraction.Log(string.Format("[{0}] Disposing socket.", ToHex(SessionId)));
19001914
_socket.Dispose();
1915+
DiagnosticAbstraction.Log(string.Format("[{0}] Disposed socket.", ToHex(SessionId)));
19011916
_socket = null;
19021917
}
19031918
}
@@ -1913,8 +1928,8 @@ private void MessageListener()
19131928
{
19141929
var readSockets = new List<Socket> {_socket};
19151930

1916-
// remain in message loop until socket is shut down
1917-
while (true)
1931+
// remain in message loop until socket is shut down or until we're disconnecting
1932+
while (!_isDisconnecting)
19181933
{
19191934
#if FEATURE_SOCKET_POLL
19201935
Socket.Select(readSockets, null, null, -1);

0 commit comments

Comments
 (0)