File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
366366 override readonly mongoLogger : MongoLogger | undefined ;
367367 /** @internal */
368368 private connectionLock ?: Promise < this> ;
369+ /** @internal */
370+ private closeLock ?: Promise < void >
369371
370372 /**
371373 * The consolidate, parsed, transformed and merged options.
@@ -638,6 +640,20 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
638640 * @param force - Force close, emitting no events
639641 */
640642 async close ( force = false ) : Promise < void > {
643+ if ( this . closeLock ) {
644+ return await this . closeLock ;
645+ }
646+
647+ try {
648+ this . closeLock = this . _close ( force ) ;
649+ await this . closeLock ;
650+ } finally {
651+ // release
652+ this . connectionLock = undefined ;
653+ }
654+ }
655+
656+ async _close ( force = false ) : Promise < void > {
641657 // There's no way to set hasBeenClosed back to false
642658 Object . defineProperty ( this . s , 'hasBeenClosed' , {
643659 value : true ,
You can’t perform that action at this time.
0 commit comments