Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5804

Add intermediary state when aborting transactions

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Transactions
    • 2
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Scenario: we start a transaction and use it in multiple queries, all good, commit works as expected so does abort. The problem begins when you throw an unhandled exception.

      When this happens we catch and run the following:

      for await (const s of Object.keys(this.mongodbSessions)) {
        if (this.mongodbSessions[s].inTransaction()) {
          console.log(`session name: ${s} > ${this.mongodbSessions[s].inTransaction()}`);
          await this.mongodbSessions[s].abortTransaction();
          console.log(`session name: ${s} > I died here`);
          delete this.mongodbSessions[s];
        }
      }
      

      This code runs when we catch an unhandled exception and we handle it by aborting all transactions currently in a transaction. We get this error because the function runs twice and there's no intermediary status between in transaction and aborted.

      As a result the inTransaction() call still returns true when the await of aborted already started from the first promise resulting in the following error:

      MongoRuntimeError: Attempted illegal state transition from [TRANSACTION_ABORTED] to [TRANSACTION_ABORTED]
      

      Ideally when abortSession() is called the the status goes to ABORTING and then when the await is done it changes to ABORTED.

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: