racker/node-cassandra-client — pull request #31 by robert-chiniquy (2012-05-29 22:30:01+00:00)
Title: Fix connection close race condition

Fixes race condition in PooledConnection.shutdown()

Previously, if PooledConnection.shutdown() was called before the connection process had completed,
_closeConnections would only call ConnectionInPool.close() on each connection in the pool if that
ConnectionInPool had connected == true. If the connection process was still in-progress, connected
would be set to false, close() would not be called, and the socket would later connect, causing tests
to hang.

This adds two events to ConnectionInPool, 'connected' and 'disconnected' - 'disconnected' is not
actually needed, just added for symmetry. Instead of setting ConnectionInPool.connected directly,
call setConnected() or setDisconnected() and the appropriate event will be emitted.

ConnectionInPool.closeConnections now attaches an on('connected') handler to close the connection
if the connection completes after shutdown() has been called.