lib/z_k/pool.rb in zk-0.8.3 vs lib/z_k/pool.rb in zk-0.8.4

- old
+ new

@@ -57,12 +57,14 @@ return if (closed? or forced?) @state = :forced @pool.clear - while cnx = @connections.shift - cnx.close! + until @connections.empty? + if cnx = @connections.shift + cnx.close! + end end @state = :closed # free any waiting @@ -103,11 +105,11 @@ connection.__send__(meth, *args, &block) end end def size #:nodoc: - @connection.synchronize { @pool.size } + @mutex.synchronize { @pool.size } end def pool_state #:nodoc: @state end @@ -189,9 +191,13 @@ while true assert_open! if @pool.length > 0 cnx = @pool.shift + + # XXX(slyphon): not really sure how this case happens, but protect against it as we're + # seeing an issue in production + next if cnx.nil? # if the connection isn't connected, then set up an on_connection # handler and try the next one in the pool unless cnx.connected? logger.debug { "connection #{cnx.object_id} is not connected" }