Skip to content

Commit 13117d6

Browse files
comandeo-mongoalcaeusjmikola
authored
DRIVERS-2584 Errors handling in Convenient Transactions API (#1475)
Co-authored-by: Andreas Braun <[email protected]> Co-authored-by: Jeremy Mikola <[email protected]>
1 parent a0bac5c commit 13117d6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: source/transactions-convenient-api/transactions-convenient-api.rst

+20
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,25 @@ MongoClient within the callback in order to execute operations within the
299299
transaction. Per the `Driver Session`_ specification, ClientSessions should
300300
already provide access to a client object.
301301

302+
Handling errors inside the callback
303+
-----------------------------------
304+
305+
Drivers MUST document that the callback MUST NOT silently handle command errors
306+
without allowing such errors to propagate. Command errors may abort the transaction
307+
on the server, and an attempt to commit the transaction will be rejected with
308+
``NoSuchTransaction`` error.
309+
310+
For example, ``DuplicateKeyError`` is an error that aborts a transaction on the
311+
server. If the callback catches ``DuplicateKeyError`` and does not re-throw it,
312+
the driver will attempt to commit the transaction. The server will reject the
313+
commit attempt with ``NoSuchTransaction`` error. This error has the
314+
"TransientTransactionError" label and the driver will retry the commit. This
315+
will result in an infinite loop.
316+
317+
Drivers MUST recommend that the callback re-throw command errors if they
318+
need to be handled inside the callback. Drivers SHOULD also recommend using
319+
Core Transaction API if a user wants to handle errors in a custom way.
320+
302321
Test Plan
303322
=========
304323

@@ -494,6 +513,7 @@ client-side operation timeout, withTransaction can continue to use the
494513
Changes
495514
=======
496515

516+
:2023-11-22: Document error handling inside the callback.
497517
:2022-10-05: Remove spec front matter and reformat changelog.
498518
:2022-01-19: withTransaction applies timeouts per the client-side operations
499519
timeout specification.

Diff for: source/transactions/transactions.rst

+9
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,13 @@ label. For example:
982982
continue
983983
raise
984984
985+
Handling command errors
986+
-----------------------
987+
988+
Drivers MUST document that command errors inside a transaction may abort
989+
the transaction on the server. An attempt to commit such transaction will be
990+
rejected with ``NoSuchTransaction`` error.
991+
985992
**Test Plan**
986993
-------------
987994

@@ -1407,6 +1414,8 @@ durable, which achieves the primary objective of avoiding duplicate commits.
14071414
**Changelog**
14081415
-------------
14091416

1417+
:2023-11-22: Specify that non-transient transaction errors abort the transaction
1418+
on the server.
14101419
:2022-10-05: Remove spec front matter and reformat changelog
14111420
:2022-01-25: Mention the additional case of a retryable handshake error
14121421
:2022-01-19: Deprecate maxCommitTimeMS in favor of timeoutMS.

0 commit comments

Comments
 (0)