From d3dd724ca384c4af5ce927c8d0a2cd002ce73253 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 28 May 2024 14:14:38 -0400 Subject: [PATCH 1/3] docs(NODE-6191): clarify that operations should not be parallelized in transactions --- src/sessions.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sessions.ts b/src/sessions.ts index b766d40e28..5867e988ea 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -369,6 +369,11 @@ export class ClientSession extends TypedEventEmitter { /** * Starts a new transaction with the given options. * + * @remarks + * **IMPORTANT**: Running operations in parallel is not supported during a transaction. The use of `Promise.all`, + * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is + * undefined behaviour. + * * @param options - Options for the transaction */ startTransaction(options?: TransactionOptions): void { @@ -449,6 +454,10 @@ export class ClientSession extends TypedEventEmitter { * - If the transaction is manually aborted within the provided function it will not throw. * - If the driver needs to attempt to retry the operations, the provided function may be called multiple times. * + * **IMPORTANT:** Running operations in parallel is not supported during a transaction. The use of `Promise.all`, + * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is + * undefined behaviour. + * * Checkout a descriptive example here: * @see https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions * From 0fac93545828bd6ea8438805a32426fb6e171f64 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 28 May 2024 14:27:55 -0400 Subject: [PATCH 2/3] update doc comment --- src/sessions.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sessions.ts b/src/sessions.ts index 5867e988ea..dff3cb09d3 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -448,15 +448,17 @@ export class ClientSession extends TypedEventEmitter { * * **IMPORTANT:** This method requires the function passed in to return a Promise. That promise must be made by `await`-ing all operations in such a way that rejections are propagated to the returned promise. * + * **IMPORTANT:** Running operations in parallel is not supported during a transaction. The use of `Promise.all`, + * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is + * undefined behaviour. + * + * * @remarks * - If all operations successfully complete and the `commitTransaction` operation is successful, then the provided function will return the result of the provided function. * - If the transaction is unable to complete or an error is thrown from within the provided function, then the provided function will throw an error. * - If the transaction is manually aborted within the provided function it will not throw. * - If the driver needs to attempt to retry the operations, the provided function may be called multiple times. * - * **IMPORTANT:** Running operations in parallel is not supported during a transaction. The use of `Promise.all`, - * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is - * undefined behaviour. * * Checkout a descriptive example here: * @see https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions From 1b1ed0912d19263106b00f139c2f99d3bb3359b6 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 28 May 2024 15:25:44 -0400 Subject: [PATCH 3/3] Update src/sessions.ts Co-authored-by: Aditi Khare <106987683+aditi-khare-mongoDB@users.noreply.github.com> --- src/sessions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sessions.ts b/src/sessions.ts index dff3cb09d3..20699d24ac 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -459,7 +459,6 @@ export class ClientSession extends TypedEventEmitter { * - If the transaction is manually aborted within the provided function it will not throw. * - If the driver needs to attempt to retry the operations, the provided function may be called multiple times. * - * * Checkout a descriptive example here: * @see https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions *