-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Transactions
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.