Skip to content

Commit 51bd5f5

Browse files
joshbsiegelkevinAlbs
authored andcommitted
CDRIVER-4755 document error handing in transactions (#1711)
* doc updates to clarify cb behavior * add clarification for when cmd inside of transaction fails * move command failure warning to different doc
1 parent 3baad5f commit 51bd5f5

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/libmongoc/doc/mongoc_client_session_start_transaction.rst

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Start a multi-document transaction for all following operations in this session.
1818

1919
The transaction must be completed with :symbol:`mongoc_client_session_commit_transaction` or :symbol:`mongoc_client_session_abort_transaction`. An in-progress transaction is automatically aborted by :symbol:`mongoc_client_session_destroy`.
2020

21+
If a command inside of the transaction fails, it may cause the transaction on the server to be aborted. An attempt to commit such transaction will be rejected with ``NoSuchTransaction`` error.
22+
2123
Parameters
2224
----------
2325

src/libmongoc/doc/mongoc_client_session_with_transaction.rst

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ This method has an internal time limit of 120 seconds, and will retry until that
2222

2323
``cb`` should not attempt to start new transactions, but should simply run operations meant to be contained within a transaction. The ``cb`` does not need to commit transactions; this is handled by the :symbol:`mongoc_client_session_with_transaction`. If ``cb`` does commit or abort a transaction, however, this method will return without taking further action.
2424

25+
If a command inside ``cb`` fails, it may cause the transaction on the server to be aborted. This situation is normally handled transparently by the driver. However, if the application does not return that error from ``cb``, the driver will not be able to determine whether the transaction was aborted or not. The driver will then retry ``cb`` indefinitely. To avoid this situation, the application MUST NOT silently handle errors within ``cb``. If the application needs to handle errors within ``cb``, it MUST return them after doing so.
26+
2527
The parameter ``reply`` is initialized even upon failure to simplify memory management.
2628

2729
Parameters

0 commit comments

Comments
 (0)