@@ -22,7 +22,7 @@ import { MONGO_CLIENT_EVENTS } from './constants';
2222import { type AbstractCursor } from './cursor/abstract_cursor' ;
2323import { Db , type DbOptions } from './db' ;
2424import type { Encrypter } from './encrypter' ;
25- import { MongoInvalidArgumentError } from './error' ;
25+ import { MongoClientClosedError , MongoInvalidArgumentError } from './error' ;
2626import { MongoClientAuthProviders } from './mongo_client_auth_providers' ;
2727import {
2828 type LogComponentSeveritiesClientOptions ,
@@ -692,7 +692,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
692692 /* @internal */
693693 private async _close ( force = false ) : Promise < void > {
694694 try {
695- this . closeController . abort ( ) ;
696695 // There's no way to set hasBeenClosed back to false
697696 Object . defineProperty ( this . s , 'hasBeenClosed' , {
698697 value : true ,
@@ -701,6 +700,12 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
701700 writable : false
702701 } ) ;
703702
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+
704709 const activeCursorCloses = Array . from ( this . s . activeCursors , cursor => cursor . close ( ) ) ;
705710 this . s . activeCursors . clear ( ) ;
706711
@@ -749,7 +754,9 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
749754 await encrypter . close ( this , force ) ;
750755 }
751756 } finally {
752- // ignore
757+ if ( ! this . closeController . signal . aborted ) {
758+ this . closeController . abort ( new MongoClientClosedError ( ) ) ;
759+ }
753760 }
754761 }
755762
0 commit comments