You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/sessions.ts
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -435,18 +435,26 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
435
435
/**
436
436
* Starts a transaction and runs a provided function, ensuring the commitTransaction is always attempted when all operations run in the function have completed.
437
437
*
438
-
* **IMPORTANT:** This method requires the user to return a Promise, and `await` all operations.
438
+
* **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.
439
439
*
440
440
* @remarks
441
-
* This function:
442
-
* - If all operations successfully complete and the `commitTransaction` operation is successful, then this function will return the result of the provided function.
443
-
* - If the transaction is unable to complete or an error is thrown from within the provided function, then this function will throw an error.
441
+
* - If all operations successfully complete and the `commitTransaction` operation is successful, then the provided function will return the result of the provided function.
442
+
* - 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.
444
443
* - If the transaction is manually aborted within the provided function it will not throw.
445
-
* - May be called multiple times if the driver needs to attempt to retry the operations.
444
+
* - If the driver needs to attempt to retry the operations, the provided function may be called multiple times.
* - It may cause the transaction on the server to be aborted.
451
+
* - This situation is normally handled transparently by the driver.
452
+
* - However, if the application catches such an error and does not rethrow it, the driver will not be able to determine whether the transaction was aborted or not.
453
+
* - The driver will then retry the transaction indefinitely.
454
+
*
455
+
* To avoid this situation, the application must not silently handle errors within the provided function.
456
+
* If the application needs to handle errors within, it must await all operations such that if an operation is rejected it becomes the rejection of the callback function passed into withTransaction.
457
+
*
450
458
* @param fn - callback to run within a transaction
451
459
* @param options - optional settings for the transaction
0 commit comments