Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when both server and client disconnect #80

Closed
drieseng opened this issue Sep 4, 2016 · 0 comments
Closed

Race condition when both server and client disconnect #80

drieseng opened this issue Sep 4, 2016 · 0 comments
Assignees
Labels
Milestone

Comments

@drieseng
Copy link
Member

drieseng commented Sep 4, 2016

When a server sends a SSH_MSG_DISCONNECT and the client invokes Disconnect() or Dispose() at the same time, this can lead to one of following exceptions (from issue #58):

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
at System.Net.Sockets.Socket.get_Available()
at Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected)
at Renci.SshNet.Session.get_IsConnected()
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message)
at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message)
at Renci.SshNet.Session.Disconnect()
at Renci.SshNet.BaseClient.Disconnect()
at DBAService.Logic.FileTransfer.DbaSftpClient.CloseConnection() at System.Net.Sockets.Socket.get_Available()
at Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected)
at Renci.SshNet.Session.get_IsConnected()
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message)
at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message)
at Renci.SshNet.Session.Disconnect()
at Renci.SshNet.BaseClient.Disconnect()
at DBAService.Logic.FileTransfer.DbaSftpClient.CloseConnection()

or

System.NullReferenceException: Object reference not set to an instance of an object.
at Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected)
at Renci.SshNet.Session.get_IsConnected()
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message)
at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message)
at Renci.SshNet.Session.Disconnect()
at Renci.SshNet.BaseClient.Disconnect()
at DBAService.Logic.FileTransfer.DbaSftpClient.CloseConnection() at Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected)
at Renci.SshNet.Session.get_IsConnected()
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message)
at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message)
at Renci.SshNet.Session.Disconnect()
at Renci.SshNet.BaseClient.Disconnect()
at DBAService.Logic.FileTransfer.DbaSftpClient.CloseConnection()

@drieseng drieseng changed the title Race condition when server closes session Race condition when disconnects Sep 4, 2016
@drieseng drieseng changed the title Race condition when disconnects Race condition when both server and client disconnect Sep 4, 2016
drieseng added a commit that referenced this issue Sep 4, 2016
Introduce dispose lock to resolve race condition in IsConnected/IsSocketConnected.
Rename _socketLock to _socketWriteLock
Eliminate extra allocations in ReceiveMessage, and combine two socket reads.
Use separate lock to eliminate race condition in IsSocketConnected between Poll and checking the Available property.
Modify SocketRead(int length, byte[] buffer) to also take offset.
Modify MessageListener to use Select instead of blocking Receive.

Fixes issue #80.
@drieseng drieseng added the bug label Sep 11, 2016
@drieseng drieseng added this to the 2016.1.0 milestone Sep 11, 2016
@drieseng drieseng self-assigned this Sep 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant