Skip to content

Commit d1b4562

Browse files
committed
wip: testing
1 parent 6af545c commit d1b4562

File tree

6 files changed

+343
-44
lines changed

6 files changed

+343
-44
lines changed

Diff for: src/client-side-encryption/auto_encrypter.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { kDecorateResult } from '../constants';
1111
import { getMongoDBClientEncryption } from '../deps';
1212
import { MongoRuntimeError } from '../error';
1313
import { MongoClient, type MongoClientOptions } from '../mongo_client';
14+
import { type Abortable } from '../mongo_types';
1415
import { MongoDBCollectionNamespace } from '../utils';
1516
import { autoSelectSocketOptions } from './client_encryption';
1617
import * as cryptoCallbacks from './crypto_callbacks';
@@ -372,8 +373,10 @@ export class AutoEncrypter {
372373
async encrypt(
373374
ns: string,
374375
cmd: Document,
375-
options: CommandOptions = {}
376+
options: CommandOptions & Abortable = {}
376377
): Promise<Document | Uint8Array> {
378+
options.signal?.throwIfAborted();
379+
377380
if (this._bypassEncryption) {
378381
// If `bypassAutoEncryption` has been specified, don't encrypt
379382
return cmd;
@@ -407,7 +410,12 @@ export class AutoEncrypter {
407410
/**
408411
* Decrypt a command response
409412
*/
410-
async decrypt(response: Uint8Array, options: CommandOptions = {}): Promise<Uint8Array> {
413+
async decrypt(
414+
response: Uint8Array,
415+
options: CommandOptions & Abortable = {}
416+
): Promise<Uint8Array> {
417+
options.signal?.throwIfAborted();
418+
411419
const context = this._mongocrypt.makeDecryptionContext(response);
412420

413421
context.id = this._contextCounter++;

Diff for: src/client-side-encryption/state_machine.ts

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export class StateMachine {
206206
let result: Uint8Array | null = null;
207207

208208
while (context.state !== MONGOCRYPT_CTX_DONE && context.state !== MONGOCRYPT_CTX_ERROR) {
209+
options.signal?.throwIfAborted();
209210
debug(`[context#${context.id}] ${stateToString.get(context.state) || context.state}`);
210211

211212
switch (context.state) {

Diff for: src/cmap/connection.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
474474
);
475475
}
476476

477-
for await (const response of this.readMany({ timeoutContext: options.timeoutContext })) {
477+
for await (const response of this.readMany({
478+
timeoutContext: options.timeoutContext,
479+
signal: options.signal
480+
})) {
478481
this.socket.setTimeout(0);
479482
const bson = response.parse();
480483

Diff for: src/cmap/wire_protocol/on_data.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export function onData(
2424
emitter: EventEmitter,
2525
{ timeoutContext, signal }: { timeoutContext?: TimeoutContext } & Abortable
2626
) {
27+
signal?.throwIfAborted();
28+
2729
// Setup pending events and pending promise lists
2830
/**
2931
* When the caller has not yet called .next(), we store the

Diff for: src/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,8 @@ export const randomBytes = promisify(crypto.randomBytes);
13511351
* @param name - An event name to wait for
13521352
*/
13531353
export async function once<T>(ee: EventEmitter, name: string, options?: Abortable): Promise<T> {
1354+
options?.signal?.throwIfAborted();
1355+
13541356
const { promise, resolve, reject } = promiseWithResolvers<T>();
13551357
const onEvent = (data: T) => resolve(data);
13561358
const onError = (error: Error) => reject(error);

0 commit comments

Comments
 (0)