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

Commit 2f671c3

Browse files
committed
fix(connection): fixing leak in 3.0.0
1 parent d7cd5cd commit 2f671c3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Diff for: lib/connection/connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ Connection.prototype.connect = function(_options) {
600600
});
601601
self.connection.setTimeout(self.connectionTimeout);
602602
} else {
603-
self.connection.on('connect', function() {
603+
self.connection.once('connect', function() {
604604
// Set socket timeout instead of connection timeout
605605
self.connection.setTimeout(self.socketTimeout);
606606
// Emit connect event

Diff for: test/tests/functional/pool_tests.js

+30
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,36 @@ describe('Pool tests', function() {
3939
}
4040
});
4141

42+
it('Should only listen on connect once', {
43+
metadata: { requires: { topology: 'single' } },
44+
45+
test: function(done) {
46+
// Enable connections accounting
47+
Connection.enableConnectionAccounting();
48+
49+
// Attempt to connect
50+
var pool = new Pool(null, {
51+
host: this.configuration.host,
52+
port: this.configuration.port,
53+
bson: new Bson(),
54+
messageHandler: function() {}
55+
});
56+
57+
// Add event listeners
58+
pool.on('connect', function(_pool) {
59+
var connections = _pool.allConnections();
60+
expect(connections).to.have.lengthOf(1).and.to.have;
61+
expect(connections[0].connection.listenerCount('connect')).to.equal(1);
62+
_pool.destroy();
63+
Connection.disableConnectionAccounting();
64+
done();
65+
});
66+
67+
// Start connection
68+
pool.connect();
69+
}
70+
});
71+
4272
it('should correctly write ismaster operation to the server', {
4373
metadata: { requires: { topology: 'single' } },
4474

0 commit comments

Comments
 (0)