@@ -641,25 +641,27 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
641641 }
642642
643643 /**
644- * Cleans up client-side resources used by the MongoCLient and . This includes:
644+ * Cleans up client-side resources used by the MongoClient.
645645 *
646- * - Closes all open, unused connections (see note).
646+ * This includes:
647+ *
648+ * - Closes in-use connections.
649+ * - Closes all active cursors.
647650 * - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
651+ * - aborts in progress transactions if is one related to the session.
648652 * - Ends all unused sessions server-side.
653+ * - Closes all remaining idle connections.
649654 * - Cleans up any resources being used for auto encryption if auto encryption is enabled.
650655 *
651- * @remarks Any in-progress operations are not killed and any connections used by in progress operations
652- * will be cleaned up lazily as operations finish.
653- *
654- * @param force - Force close, emitting no events
656+ * @param _force - currently an unused flag that has no effect. Defaults to `false`.
655657 */
656- async close ( force = false ) : Promise < void > {
658+ async close ( _force = false ) : Promise < void > {
657659 if ( this . closeLock ) {
658660 return await this . closeLock ;
659661 }
660662
661663 try {
662- this . closeLock = this . _close ( force ) ;
664+ this . closeLock = this . _close ( ) ;
663665 await this . closeLock ;
664666 } finally {
665667 // release
@@ -668,7 +670,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
668670 }
669671
670672 /* @internal */
671- private async _close ( force = false ) : Promise < void > {
673+ private async _close ( ) : Promise < void > {
672674 // There's no way to set hasBeenClosed back to false
673675 Object . defineProperty ( this . s , 'hasBeenClosed' , {
674676 value : true ,
@@ -677,6 +679,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
677679 writable : false
678680 } ) ;
679681
682+ this . topology ?. closeCheckedOutConnections ( ) ;
683+
680684 const activeCursorCloses = Array . from ( this . s . activeCursors , cursor => cursor . close ( ) ) ;
681685 this . s . activeCursors . clear ( ) ;
682686
@@ -722,7 +726,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
722726
723727 const { encrypter } = this . options ;
724728 if ( encrypter ) {
725- await encrypter . close ( this , force ) ;
729+ await encrypter . close ( this ) ;
726730 }
727731 }
728732
0 commit comments