Skip to content

Commit

Permalink
Avoid calling closed? outside of synchronize block
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
djmb committed Apr 1, 2024
1 parent 952d3be commit 552648e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sshkit/backends/connection_pool/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def evict
# Peek at the first connection to see if it is still fresh. If so, we can
# return right away without needing to use `synchronize`.
first_expires_at, first_conn = connections.first
return if (first_expires_at.nil? || fresh?(first_expires_at)) && !closed?(first_conn)
return if (first_expires_at.nil? || fresh?(first_expires_at))

connections.synchronize do
fresh, stale = connections.partition do |expires_at, conn|
Expand Down

0 comments on commit 552648e

Please sign in to comment.