Open
Description
using TcpView you will see many orphan connections, loosing their process(id). After some time (1 Min), the connection will be close by the OS. (use-case: The image shows the connections, login/logout in to a Sftp-Server every 5 sec, to check for new files)
To avoid oprhan connections [TimeWait) add a delay of 100ms! I think, the wait leads to a direct thread-change to fullfill the sending the disconnect message!?
Insert a delay of 100ms between
-> TryDisconnectSend
add the delay of 100ms
-> socket.ShutDown()
In Session.cs
...
private void Disconnect(DisconnectReason reason, string message)
{
// transition to disconnecting state to avoid throwing exceptions while cleaning up, and to
// ensure any exceptions that are raised do not overwrite the exception that is set
_isDisconnecting = true;
// send disconnect message to the server if the connection is still open (IsConnected is not correct!)
// and the disconnect message has not yet been sent
//
// note that this should also cause the listener loop to be interrupted as
// the server should respond by closing the socket
_socketDisposeLock.Wait();
var socketConnected = _socket != null && _socket.IsConnected();
_socketDisposeLock.Release();
if (socketConnected || IsConnected)
{
using (var delayEvent = new ManualResetEvent(initialState: false))
{
TrySendDisconnect(reason, message);
delayEvent.WaitOne(TimeSpan.FromMilliseconds(100));
}
}
// disconnect socket, and dispose it
SocketDisconnectAndDispose();
}
Metadata
Metadata
Assignees
Labels
No labels