@@ -415,7 +415,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
415
415
*/
416
416
clear ( options : { serviceId ?: ObjectId ; interruptInUseConnections ?: boolean } = { } ) : void {
417
417
const { serviceId } = options ;
418
- const interruptInUseConnections = options . interruptInUseConnections ?? false ;
419
418
if ( this . closed ) {
420
419
return ;
421
420
}
@@ -438,10 +437,9 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
438
437
) ;
439
438
return ;
440
439
}
441
-
442
- const oldGeneration = this [ kGeneration ] ;
443
-
444
440
// handle non load-balanced case
441
+ const interruptInUseConnections = options . interruptInUseConnections ?? false ;
442
+ const oldGeneration = this [ kGeneration ] ;
445
443
this [ kGeneration ] += 1 ;
446
444
const alreadyPaused = this [ kPoolState ] === PoolState . paused ;
447
445
this [ kPoolState ] = PoolState . paused ;
@@ -455,7 +453,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
455
453
}
456
454
457
455
process . nextTick ( ( ) =>
458
- this . pruneConnections ( { minGeneration : oldGeneration , interruptInUseConnections } )
456
+ this . interruptInUseConnections ( { interruptInUseConnections , minGeneration : oldGeneration } )
459
457
) ;
460
458
461
459
this . processWaitQueue ( ) ;
@@ -468,41 +466,29 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
468
466
* Only connections where `connection.generation <= minGeneration` are killed. Connections are closed with a
469
467
* resumable PoolClearedOnNetworkTimeoutError.
470
468
*/
471
- private pruneConnections ( {
469
+ private interruptInUseConnections ( {
472
470
interruptInUseConnections,
473
471
minGeneration
474
472
} : {
475
473
interruptInUseConnections : boolean ;
476
474
minGeneration : number ;
477
475
} ) {
478
- this [ kConnections ] . prune ( connection => {
476
+ if ( ! interruptInUseConnections ) {
477
+ return ;
478
+ }
479
+ for ( const connection of this [ kCheckedOut ] ) {
479
480
if ( connection . generation <= minGeneration ) {
481
+ this [ kCheckedOut ] . delete ( connection ) ;
480
482
connection . onError ( new PoolClearedOnNetworkError ( this ) ) ;
481
483
this . emit (
482
484
ConnectionPool . CONNECTION_CLOSED ,
483
485
new ConnectionClosedEvent ( this , connection , 'stale' )
484
486
) ;
485
-
486
- return true ;
487
487
}
488
- return false ;
489
- } ) ;
490
-
491
- if ( interruptInUseConnections ) {
492
- for ( const connection of this [ kCheckedOut ] ) {
493
- if ( connection . generation <= minGeneration ) {
494
- this [ kCheckedOut ] . delete ( connection ) ;
495
- connection . onError ( new PoolClearedOnNetworkError ( this ) ) ;
496
- this . emit (
497
- ConnectionPool . CONNECTION_CLOSED ,
498
- new ConnectionClosedEvent ( this , connection , 'stale' )
499
- ) ;
500
- }
501
- }
502
-
503
- // TODO(NODE-4784): track pending connections and cancel
504
- // this[kCancellationToken].emit('cancel');
505
488
}
489
+
490
+ // TODO(NODE-4784): track pending connections and cancel
491
+ // this[kCancellationToken].emit('cancel');
506
492
}
507
493
508
494
/** Close the pool */
0 commit comments