@@ -28,7 +28,6 @@ import { CancellationToken, TypedEventEmitter } from '../mongo_types';
28
28
import type { Server } from '../sdam/server' ;
29
29
import {
30
30
type Callback ,
31
- eachAsync ,
32
31
List ,
33
32
makeCounter ,
34
33
promiseWithResolvers ,
@@ -493,25 +492,16 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
493
492
private interruptInUseConnections ( minGeneration : number ) {
494
493
for ( const connection of this [ kCheckedOut ] ) {
495
494
if ( connection . generation <= minGeneration ) {
496
- this . checkIn ( connection ) ;
497
495
connection . onError ( new PoolClearedOnNetworkError ( this ) ) ;
496
+ this . checkIn ( connection ) ;
498
497
}
499
498
}
500
499
}
501
500
502
501
/** Close the pool */
503
- close ( callback : Callback < void > ) : void ;
504
- close ( options : CloseOptions , callback : Callback < void > ) : void ;
505
- close ( _options ?: CloseOptions | Callback < void > , _cb ?: Callback < void > ) : void {
506
- let options = _options as CloseOptions ;
507
- const callback = ( _cb ?? _options ) as Callback < void > ;
508
- if ( typeof options === 'function' ) {
509
- options = { } ;
510
- }
511
-
512
- options = Object . assign ( { force : false } , options ) ;
502
+ close ( ) : void {
513
503
if ( this . closed ) {
514
- return callback ( ) ;
504
+ return ;
515
505
}
516
506
517
507
// immediately cancel any in-flight connections
@@ -526,21 +516,15 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
526
516
this . clearMinPoolSizeTimer ( ) ;
527
517
this . processWaitQueue ( ) ;
528
518
529
- eachAsync < Connection > (
530
- this [ kConnections ] . toArray ( ) ,
531
- ( conn , cb ) => {
532
- this . emitAndLog (
533
- ConnectionPool . CONNECTION_CLOSED ,
534
- new ConnectionClosedEvent ( this , conn , 'poolClosed' )
535
- ) ;
536
- conn . destroy ( { force : ! ! options . force } , cb ) ;
537
- } ,
538
- err => {
539
- this [ kConnections ] . clear ( ) ;
540
- this . emitAndLog ( ConnectionPool . CONNECTION_POOL_CLOSED , new ConnectionPoolClosedEvent ( this ) ) ;
541
- callback ( err ) ;
542
- }
543
- ) ;
519
+ for ( const conn of this [ kConnections ] ) {
520
+ this . emitAndLog (
521
+ ConnectionPool . CONNECTION_CLOSED ,
522
+ new ConnectionClosedEvent ( this , conn , 'poolClosed' )
523
+ ) ;
524
+ conn . destroy ( ) ;
525
+ }
526
+ this [ kConnections ] . clear ( ) ;
527
+ this . emitAndLog ( ConnectionPool . CONNECTION_POOL_CLOSED , new ConnectionPoolClosedEvent ( this ) ) ;
544
528
}
545
529
546
530
/**
@@ -592,7 +576,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
592
576
new ConnectionClosedEvent ( this , connection , reason )
593
577
) ;
594
578
// destroy the connection
595
- process . nextTick ( ( ) => connection . destroy ( { force : false } ) ) ;
579
+ connection . destroy ( ) ;
596
580
}
597
581
598
582
private connectionIsStale ( connection : Connection ) {
@@ -648,7 +632,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
648
632
// The pool might have closed since we started trying to create a connection
649
633
if ( this [ kPoolState ] !== PoolState . ready ) {
650
634
this [ kPending ] -- ;
651
- connection . destroy ( { force : true } ) ;
635
+ connection . destroy ( ) ;
652
636
callback ( this . closed ? new PoolClosedError ( this ) : new PoolClearedError ( this ) ) ;
653
637
return ;
654
638
}
0 commit comments