Embed the DBTransaction.destroy
into the DBTransaction.commit
and DBTransaction.rollback
.
#56
Labels
DBTransaction.destroy
into the DBTransaction.commit
and DBTransaction.rollback
.
#56
Specification
Previously the
destroy
call was called insidecommit
androllback
. This has since been removed since #53, since theResourceAcquire<DBTransaction>
already calleddestroy
and it was unnecessary to calldestroy
twice.However we discovered in the EFS (MatrixAI/js-encryptedfs#74 (comment)), a dangling/floating promise could still have a reference to the transaction and end up trying to do a
get
on a transaction that is already committed. This ends up with the C++ code throwing aTRANSACTION_COMMITTED
exception. This is not caught on the JS side because it was not expected to happen.We are relying on the
@ready
decorator to protect theget
methods and other methods if they are called when the transaction is already destroyed. But it does appear that there can be time between commit/rollback and destruction because these are separate functions.We could make commit/rollback the equivalent of a destruction by applying the commit/rollback code inside the
destroy
call. And makedestroy
have atype: 'commit' | 'rollback'
union. This wayDBTransaction.commit
andDBTransaction.rollback
is just forwarding the call to thedestroy
.This can simplify our transaction lifecycle, and ensure that methods cannot be called when a commit/destroy is being called, because this means it's in the process of being destroyed. It could also mean that we can use the ready blocking that we found we couldn't do when attempting to fix the dangling transactions during
db.stop()
.Additional context
db.stop()
is destroying dangling transactionsTasks
The text was updated successfully, but these errors were encountered: