@@ -560,18 +560,19 @@ Pool.prototype.connect = function(callback) {
560
560
}
561
561
562
562
stateTransition ( this , CONNECTED ) ;
563
- if ( typeof callback === 'function' ) {
564
- callback ( null , conn ) ;
565
- } else {
566
- this . emit ( 'connect' , this , conn ) ;
567
- }
568
563
569
564
// create min connections
570
565
if ( this . minSize ) {
571
566
for ( let i = 0 ; i < this . minSize ; i ++ ) {
572
567
createConnection ( this ) ;
573
568
}
574
569
}
570
+
571
+ if ( typeof callback === 'function' ) {
572
+ callback ( null , conn ) ;
573
+ } else {
574
+ this . emit ( 'connect' , this , conn ) ;
575
+ }
575
576
} ) ;
576
577
} ;
577
578
@@ -687,7 +688,6 @@ Pool.prototype.destroy = function(force, callback) {
687
688
}
688
689
689
690
destroy ( self , connections , { force : false } , callback ) ;
690
- // } else if (self.queue.length > 0 && !this.reconnectId) {
691
691
} else {
692
692
// Ensure we empty the queue
693
693
_execute ( self ) ( ) ;
@@ -942,7 +942,7 @@ function removeConnection(self, connection) {
942
942
}
943
943
944
944
function createConnection ( pool , callback ) {
945
- if ( pool . state === DESTROYED || pool . state === DESTROYING ) {
945
+ if ( pool . state === DESTROYED ) {
946
946
if ( typeof callback === 'function' ) {
947
947
callback ( new MongoError ( 'Cannot create connection when pool is destroyed' ) ) ;
948
948
}
@@ -983,7 +983,7 @@ function createConnection(pool, callback) {
983
983
}
984
984
985
985
// the pool might have been closed since we started creating the connection
986
- if ( pool . state === DESTROYED || pool . state === DESTROYING ) {
986
+ if ( pool . state === DESTROYED ) {
987
987
if ( typeof callback === 'function' ) {
988
988
callback ( new MongoError ( 'Pool was destroyed after connection creation' ) ) ;
989
989
}
@@ -1050,6 +1050,12 @@ function _execute(self) {
1050
1050
if ( self . availableConnections . length === 0 ) {
1051
1051
// Flush any monitoring operations
1052
1052
flushMonitoringOperations ( self . queue ) ;
1053
+
1054
+ // attempt to grow the pool
1055
+ if ( totalConnections < self . options . size ) {
1056
+ createConnection ( self ) ;
1057
+ }
1058
+
1053
1059
break ;
1054
1060
}
1055
1061
@@ -1114,10 +1120,7 @@ function _execute(self) {
1114
1120
}
1115
1121
1116
1122
// Re-execute the operation
1117
- setTimeout ( function ( ) {
1118
- _execute ( self ) ( ) ;
1119
- } , 10 ) ;
1120
-
1123
+ setTimeout ( ( ) => _execute ( self ) ( ) , 10 ) ;
1121
1124
break ;
1122
1125
}
1123
1126
}
0 commit comments