@@ -28,7 +28,6 @@ import { CancellationToken, TypedEventEmitter } from '../mongo_types';
2828import type { Server } from '../sdam/server' ;
2929import {
3030 type Callback ,
31- eachAsync ,
3231 List ,
3332 makeCounter ,
3433 promiseWithResolvers ,
@@ -493,25 +492,16 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
493492 private interruptInUseConnections ( minGeneration : number ) {
494493 for ( const connection of this [ kCheckedOut ] ) {
495494 if ( connection . generation <= minGeneration ) {
496- this . checkIn ( connection ) ;
497495 connection . onError ( new PoolClearedOnNetworkError ( this ) ) ;
496+ this . checkIn ( connection ) ;
498497 }
499498 }
500499 }
501500
502501 /** 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 {
513503 if ( this . closed ) {
514- return callback ( ) ;
504+ return ;
515505 }
516506
517507 // immediately cancel any in-flight connections
@@ -526,21 +516,15 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
526516 this . clearMinPoolSizeTimer ( ) ;
527517 this . processWaitQueue ( ) ;
528518
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 ) ) ;
544528 }
545529
546530 /**
@@ -592,7 +576,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
592576 new ConnectionClosedEvent ( this , connection , reason )
593577 ) ;
594578 // destroy the connection
595- process . nextTick ( ( ) => connection . destroy ( { force : false } ) ) ;
579+ connection . destroy ( ) ;
596580 }
597581
598582 private connectionIsStale ( connection : Connection ) {
@@ -648,7 +632,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
648632 // The pool might have closed since we started trying to create a connection
649633 if ( this [ kPoolState ] !== PoolState . ready ) {
650634 this [ kPending ] -- ;
651- connection . destroy ( { force : true } ) ;
635+ connection . destroy ( ) ;
652636 callback ( this . closed ? new PoolClosedError ( this ) : new PoolClearedError ( this ) ) ;
653637 return ;
654638 }
0 commit comments