diff options
author | sersut <serdar@opscode.com> | 2013-06-13 13:56:30 -0700 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2013-06-13 13:56:30 -0700 |
commit | ed24d841fb4471422b7776698af381aab6ea375c (patch) | |
tree | 4a2d296c8623ce19c1b341877806294d9f6767de | |
parent | b659f2884b2c9abdbe3bbf3c844937a0799ed5ac (diff) | |
download | net-ssh-multi-ed24d841fb4471422b7776698af381aab6ea375c.tar.gz |
Solve the race condition while handling concurrent connections.
-rw-r--r-- | lib/net/ssh/multi/session.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/net/ssh/multi/session.rb b/lib/net/ssh/multi/session.rb index 333fdf3..2e2468f 100644 --- a/lib/net/ssh/multi/session.rb +++ b/lib/net/ssh/multi/session.rb @@ -476,7 +476,12 @@ module Net; module SSH; module Multi return connection end - @open_connections += 1 + # Only increment the open_connections count if the connection + # is not being forced. Incase of a force, it will already be + # incremented. + if !force + @open_connections += 1 + end end begin @@ -542,6 +547,10 @@ module Net; module SSH; module Multi count = concurrent_connections ? (concurrent_connections - open_connections) : @pending_sessions.length count.times do session = @pending_sessions.pop or break + # Increment the open_connections count here to prevent + # creation of connection thread again before that is + # incremented by the thread. + @session_mutex.synchronize { @open_connections += 1 } @connect_threads << Thread.new do session.replace_with(next_session(session.server, true)) end |