Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

fix(connection): fixing leak in 3.0.0 #235

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ Connection.prototype.connect = function(_options) {
});
self.connection.setTimeout(self.connectionTimeout);
} else {
self.connection.on('connect', function() {
self.connection.once('connect', function() {
// Set socket timeout instead of connection timeout
self.connection.setTimeout(self.socketTimeout);
// Emit connect event
Expand Down
47 changes: 47 additions & 0 deletions test/tests/functional/pool_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ describe('Pool tests', function() {
}
});

it.only('Should only listen on connect once', {
metadata: { requires: { topology: 'single' } },

test: function(done) {
// Enable connections accounting
Connection.enableConnectionAccounting();

// Attempt to connect
var pool = new Pool(null, {
host: this.configuration.host,
port: this.configuration.port,
bson: new Bson(),
messageHandler: function() {}
});

let connection;

// Add event listeners
pool.on('connect', function(_pool) {
var connections = _pool.allConnections();

process.nextTick(() => {
// Now that we are in next tick, connection should still exist, but there
// should be no connect listeners
expect(connection.connection.listenerCount('connect')).to.equal(0);
expect(connections).to.have.lengthOf(1);

_pool.destroy();

// Connection should be gone after destroy
expect(_pool.allConnections()).to.have.lengthOf(0);
Connection.disableConnectionAccounting();
done();
});
});

expect(pool.allConnections()).to.have.lengthOf(0);

// Start connection
pool.connect();

expect(pool.allConnections()).to.have.lengthOf(1);
connection = pool.allConnections()[0];
expect(connection.connection.listenerCount('connect')).to.equal(1);
}
});

it('should correctly write ismaster operation to the server', {
metadata: { requires: { topology: 'single' } },

Expand Down