Skip to content

Commit 55d399b

Browse files
authored
PYTHON-4019 Infinite loop in generic transactional provider due to dup keys (#2438)
1 parent fed738d commit 55d399b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
# sourceforge.net is giving a 403 error, but is still accessible from the browser.
8787
linkcheck_ignore = [
8888
"https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.md#requesting-an-immediate-check",
89+
"https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback",
8990
"https://github.com/mongodb/libmongocrypt/blob/master/bindings/python/README.rst#installing-from-source",
9091
r"https://wiki.centos.org/[\w/]*",
9192
r"https://sourceforge.net/",

pymongo/asynchronous/client_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,12 @@ async def callback(session, custom_arg, custom_kwarg=None):
660660
``with_transaction`` starts a new transaction and re-executes
661661
the ``callback``.
662662
663+
The ``callback`` MUST NOT silently handle command errors
664+
without allowing such errors to propagate. Command errors may abort the
665+
transaction on the server, and an attempt to commit the transaction will
666+
be rejected with a ``NoSuchTransaction`` error. For more information see
667+
the `transactions specification`_.
668+
663669
When :meth:`~AsyncClientSession.commit_transaction` raises an exception with
664670
the ``"UnknownTransactionCommitResult"`` error label,
665671
``with_transaction`` retries the commit until the result of the
@@ -689,6 +695,9 @@ async def callback(session, custom_arg, custom_kwarg=None):
689695
:return: The return value of the ``callback``.
690696
691697
.. versionadded:: 3.9
698+
699+
.. _transactions specification:
700+
https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback
692701
"""
693702
start_time = time.monotonic()
694703
while True:

pymongo/synchronous/client_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ def callback(session, custom_arg, custom_kwarg=None):
659659
``with_transaction`` starts a new transaction and re-executes
660660
the ``callback``.
661661
662+
The ``callback`` MUST NOT silently handle command errors
663+
without allowing such errors to propagate. Command errors may abort the
664+
transaction on the server, and an attempt to commit the transaction will
665+
be rejected with a ``NoSuchTransaction`` error. For more information see
666+
the `transactions specification`_.
667+
662668
When :meth:`~ClientSession.commit_transaction` raises an exception with
663669
the ``"UnknownTransactionCommitResult"`` error label,
664670
``with_transaction`` retries the commit until the result of the
@@ -688,6 +694,9 @@ def callback(session, custom_arg, custom_kwarg=None):
688694
:return: The return value of the ``callback``.
689695
690696
.. versionadded:: 3.9
697+
698+
.. _transactions specification:
699+
https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback
691700
"""
692701
start_time = time.monotonic()
693702
while True:

0 commit comments

Comments
 (0)