Avoid calling closed? outside of synchronize block#534
Conversation
`closed?` calls `process` on the connection which is not safe because we have not synchronised the connection pool. Another thread might concurrently checkout the connection and start sending commands as well.
|
When using SSHKit with a 100+ hosts, we sometimes get IOErrors like this: Debugging showed that a packet was being sent to the remote server twice, which was causing it to close the connection. This was caused by two threads using the connection concurrently - the eviction thread and one of the SSHKit parallel runner threads. The duplicate packets came from here in net-ssh, where both threads call Looking at the eviction code, the call to The check looks like a performance optimisation, so I think it should be safe to remove. We've not seen the errors again with this fix running. |
mattbrictson
left a comment
There was a problem hiding this comment.
Thanks for the fix! Could you make the following change to address the rubocop failure in CI?
Co-authored-by: Matt Brictson <matt@123mail.org>
|
Thanks for the review @mattbrictson - I've committed your suggestion. |
This includes a fix for a bug in the eviction thread that could cause this error: ``` [ERROR (IOError): Exception while executing on host foo: closed stream] ``` See capistrano/sshkit#534
closed?callsprocesson the connection which is not safe because we have not synchronised the connection pool. Another thread might concurrently checkout the connection and start sending commands as well.