Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-2584

Infinite loop in generic transactional provider due to dup keys

    • Needed
    • Hide

      Summary of necessary driver changes

      • Document that errors should not be silently handled when using convenient transaction api
      • Document that command errors may abort transaction on the server

      Commits that describes docs changes
      (and/or refer to an existing language POC if needed)

      Show
      Summary of necessary driver changes Document that errors should not be silently handled when using convenient transaction api Document that command errors may abort transaction on the server Commits that describes docs changes (and/or refer to an existing language POC if needed) specificatios@13117d6 RUBY POC
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      CDRIVER-4755 Fixed 1.27.6
      CXX-2778 Fixed 4.0.0
      CSHARP-4828 Done 2.26.0
      GODRIVER-3033 Fixed 2.1.0
      JAVA-5227 Backlog
      NODE-5721 Fixed 6.6.0
      MOTOR-1203 Backlog
      PYTHON-4019 Backlog 4.11
      PHPLIB-1298 Backlog
      RUBY-3341 Fixed 2.19.3
      RUST-1788 Fixed 2.8.0
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion CDRIVER-4755 Fixed 1.27.6 CXX-2778 Fixed 4.0.0 CSHARP-4828 Done 2.26.0 GODRIVER-3033 Fixed 2.1.0 JAVA-5227 Backlog NODE-5721 Fixed 6.6.0 MOTOR-1203 Backlog PYTHON-4019 Backlog 4.11 PHPLIB-1298 Backlog RUBY-3341 Fixed 2.19.3 RUST-1788 Fixed 2.8.0

      This is a follow-up to SERVER-34059.

      This can cause an infinite loop when implementing a generic transactional callback.

      Say my client code does something like this in pseudo-code:

      inTransaction
        execute insert with duplicate key
        catch exception, return something

      The client has caught the error and returned something rather than re-throwing. However, the `inTransaction` implementation does not know that the transaction has been aborted due to SERVER-34059 (see also https://jira.mongodb.org/browse/DOCS-11493, and so attempts to commit.

      The commit call now throws a `MongoCommandException` with error 251 (`NoSuchTransaction`). This exception also has the `TransientTransactionError` label. Therefore, per documentation (https://www.mongodb.com/docs/manual/core/transactions-in-applications/), the `inTransaction` implementation should retry the entire transaction.

      The client code then attempts the same insert resulting in dup key again, and now we have an infinite loop.

      I understand that technical issues prevent the server from not aborting the transaction on the dup key error. However, the inTransaction implementation needs some way to differentiate this case from other transient errors, allowing it to ignore the error at commit time instead of retrying. We could ignore all NoSuchTransaction errors at commit time, but that feels like it may cause other unexpected issues.

      Perhaps the error could carry an additional label? Something like "TransactionAbortedDueToDupKey" or maybe "TransactionAbortedDueToFailingOperation" or something like that?

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            rocketraman@gmail.com Raman Gupta
            Andreas Braun Andreas Braun
            Tom Selander Tom Selander
            Votes:
            0 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated: