Fix committing or rollbacking dangling transactions #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In the EFS, we came across a problem where there is a dangling transaction that is still pending. It may be neither committed, nor rollbacked, or it may be in the process of committing or rollbacking.
Either way, when the
DB.stop()
is called, it proceeds to rollback all existing transactions in the transaction reference set.Ideally, all transactions should be committed or rollbacked before the
await db.stop()
is called. However if there are dangling transactions there should be rollbacked if their status is neither committed or rollbacked, but if they have a particular status, then theDB.stop
should be waiting for those pending statuses to finish.Here we introduce a lock to be used between
DBTransaction.destroy
,DBTransaction.commit
andDBTransaction.rollback
. The basic idea is fordestroy
to wait on a commit or rollback to finish. This allows one to callawait transaction.destroy()
while the committing or rollbacking is occurring.However at the same time, if a transaction is pending to commit, but hasn't started committing. It's possible for the
DB.stop()
to already start rollbacking. If this occurs, during the resource release, the transaction will attempt to commit, in that case, an exception still occurs because the transaction is already rollbacked. This is a legitimate exception.Issues Fixed
Tasks
DB.stop()
only performsawait transaction.rollback
when the transaction is neither committing nor rollbacking. If it is in the middle of comitting or rollbacking then it should just wait for it complete.tests/DBTransaction.test.ts
await this.destroy()
fromDBTransaction.commit
andDBTransaction.rollback
, this is done automatically be the resource releaseFinal checklist