This repository was archived by the owner on Feb 4, 2022. It is now read-only.
File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -600,7 +600,7 @@ Connection.prototype.connect = function(_options) {
600
600
} ) ;
601
601
self . connection . setTimeout ( self . connectionTimeout ) ;
602
602
} else {
603
- self . connection . on ( 'connect' , function ( ) {
603
+ self . connection . once ( 'connect' , function ( ) {
604
604
// Set socket timeout instead of connection timeout
605
605
self . connection . setTimeout ( self . socketTimeout ) ;
606
606
// Emit connect event
Original file line number Diff line number Diff line change @@ -39,6 +39,36 @@ describe('Pool tests', function() {
39
39
}
40
40
} ) ;
41
41
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
+
42
72
it ( 'should correctly write ismaster operation to the server' , {
43
73
metadata : { requires : { topology : 'single' } } ,
44
74
You can’t perform that action at this time.
0 commit comments