@@ -21,6 +21,7 @@ class Connector extends DoFinish {
21
21
this . db = db ;
22
22
this . state = state ;
23
23
this . limit = state . cfg . pool . pushes ;
24
+ this . connects = [ ] ;
24
25
this . resetErrors ( ) ;
25
26
}
26
27
@@ -182,21 +183,24 @@ class Connector extends DoFinish {
182
183
}
183
184
else { // no connection yet
184
185
this . log . i ( 'Connecting %s' , pid ) ;
185
- pools . connect ( push . a , push . p , push . f , creds , this . state , this . state . cfg ) . then ( valid => {
186
+ let connect = pools . connect ( push . a , push . p , push . f , creds , this . state , this . state . cfg ) . then ( valid => {
186
187
if ( valid ) {
187
188
this . log . i ( 'Connected %s' , pid ) ;
188
189
}
189
190
else {
190
191
app . creds [ push . p ] = null ;
191
192
}
193
+ this . connects = this . connects . filter ( c => c !== connect ) ;
192
194
callback ( null , push ) ;
193
195
} , err => {
194
196
this . log . i ( 'Failed to connect %s' , pid , err ) ;
195
197
app . creds [ push . p ] = null ;
198
+ this . connects = this . connects . filter ( c => c !== connect ) ;
196
199
this . do_transform ( push , encoding , callback ) ;
197
200
// this.discardedByAppOrCreds.push(push._id);
198
201
// this.do_flush(callback, true);
199
202
} ) ;
203
+ this . connects . push ( connect ) ;
200
204
}
201
205
}
202
206
}
@@ -392,7 +396,7 @@ class Connector extends DoFinish {
392
396
* @param {function } callback callback function
393
397
*/
394
398
do_final ( callback ) {
395
- callback ( ) ;
399
+ Promise . all ( this . connects ) . then ( ( ) => callback ( ) , ( ) => callback ( ) ) ;
396
400
}
397
401
398
402
0 commit comments