Skip to content
Prev Previous commit
Next Next commit
docs and force flag
  • Loading branch information
nbbeeken committed May 2, 2025
commit 7f711c42e4292fe4ab3154f50f2dc116a05df1e5
4 changes: 2 additions & 2 deletions src/client-side-encryption/auto_encrypter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ export class AutoEncrypter {
/**
* Cleans up the `_mongocryptdClient`, if present.
*/
async teardown(force: boolean): Promise<void> {
await this._mongocryptdClient?.close(force);
async teardown(): Promise<void> {
await this._mongocryptdClient?.close();
}

/**
Expand Down
13 changes: 3 additions & 10 deletions src/encrypter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { callbackify } from 'util';

import { AutoEncrypter, type AutoEncryptionOptions } from './client-side-encryption/auto_encrypter';
import { MONGO_CLIENT_EVENTS } from './constants';
import { getMongoDBClientEncryption } from './deps';
import { MongoInvalidArgumentError, MongoMissingDependencyError } from './error';
import { MongoClient, type MongoClientOptions } from './mongo_client';
import { type Callback } from './utils';

/** @internal */
export interface EncrypterOptions {
Expand Down Expand Up @@ -98,20 +95,16 @@ export class Encrypter {
}
}

closeCallback(client: MongoClient, force: boolean, callback: Callback<void>) {
callbackify(this.close.bind(this))(client, force, callback);
}

async close(client: MongoClient, force: boolean): Promise<void> {
async close(client: MongoClient): Promise<void> {
let error;
try {
await this.autoEncrypter.teardown(force);
await this.autoEncrypter.teardown();
} catch (autoEncrypterError) {
error = autoEncrypterError;
}
const internalClient = this.internalClient;
if (internalClient != null && client !== internalClient) {
return await internalClient.close(force);
return await internalClient.close();
}
if (error != null) {
throw error;
Expand Down
18 changes: 9 additions & 9 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,23 +645,23 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
*
* This includes:
*
* - Closes all open, unused connections (see note).
* - Closes in-use connections.
* - Closes all active cursors.
* - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
* - aborts in progress transactions if is one related to the session.
* - Ends all unused sessions server-side.
* - Closes all remaining idle connections.
* - Cleans up any resources being used for auto encryption if auto encryption is enabled.
*
* @remarks Any in-progress operations are not killed and any connections used by in progress operations
* will be cleaned up lazily as operations finish.
*
* @param force - Force close, emitting no events
* @param _force - currently an unused flag that has no effect. Defaults to `false`.
*/
async close(force = false): Promise<void> {
async close(_force = false): Promise<void> {
if (this.closeLock) {
return await this.closeLock;
}

try {
this.closeLock = this._close(force);
this.closeLock = this._close();
await this.closeLock;
} finally {
// release
Expand All @@ -670,7 +670,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
}

/* @internal */
private async _close(force = false): Promise<void> {
private async _close(): Promise<void> {
// There's no way to set hasBeenClosed back to false
Object.defineProperty(this.s, 'hasBeenClosed', {
value: true,
Expand Down Expand Up @@ -726,7 +726,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements

const { encrypter } = this.options;
if (encrypter) {
await encrypter.close(this, force);
await encrypter.close(this);
}
}

Expand Down