Skip to content

Commit

Permalink
Handle double 'connect' event without touching the connection object.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Oct 9, 2012
1 parent 1af1a86 commit 1d4806f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ function ConnectionPool(poolConfig, connectionConfig) {
log: poolConfig.log,
create: function(callback) {
var connection = new PooledConnection(connectionConfig);
var connected = false;

connection.on('connect', function(err) {
if (connection.__poolConnected) {
if (connected) {
// The real 'connect' event has already been emmited by the
// connection, and processed in this function.
//
// This is now the fake connect event emmited by the acquire function,
// for applications' benefit.
return;
}

if (err) {
callback(err, null);
} else {
connection.__poolConnected = true;
connected = true;

connection.on('release', function() {
connectionEventNames.forEach(function removeAllListeners(eventName) {
Expand Down

0 comments on commit 1d4806f

Please sign in to comment.