@@ -22,7 +22,7 @@ import { MONGO_CLIENT_EVENTS } from './constants';
22
22
import { type AbstractCursor } from './cursor/abstract_cursor' ;
23
23
import { Db , type DbOptions } from './db' ;
24
24
import type { Encrypter } from './encrypter' ;
25
- import { MongoInvalidArgumentError } from './error' ;
25
+ import { MongoClientClosedError , MongoInvalidArgumentError } from './error' ;
26
26
import { MongoClientAuthProviders } from './mongo_client_auth_providers' ;
27
27
import {
28
28
type LogComponentSeveritiesClientOptions ,
@@ -692,7 +692,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
692
692
/* @internal */
693
693
private async _close ( force = false ) : Promise < void > {
694
694
try {
695
- this . closeController . abort ( ) ;
696
695
// There's no way to set hasBeenClosed back to false
697
696
Object . defineProperty ( this . s , 'hasBeenClosed' , {
698
697
value : true ,
@@ -701,6 +700,12 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
701
700
writable : false
702
701
} ) ;
703
702
703
+ if ( this . options . maxPoolSize === 1 ) {
704
+ // If maxPoolSize is 1 we won't be able to run anything
705
+ // unless we interrupt whatever is using the one connection.
706
+ this . closeController . abort ( new MongoClientClosedError ( ) ) ;
707
+ }
708
+
704
709
const activeCursorCloses = Array . from ( this . s . activeCursors , cursor => cursor . close ( ) ) ;
705
710
this . s . activeCursors . clear ( ) ;
706
711
@@ -749,7 +754,9 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
749
754
await encrypter . close ( this , force ) ;
750
755
}
751
756
} finally {
752
- // ignore
757
+ if ( ! this . closeController . signal . aborted ) {
758
+ this . closeController . abort ( new MongoClientClosedError ( ) ) ;
759
+ }
753
760
}
754
761
}
755
762
0 commit comments