Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed the DBTransaction.destroy into the DBTransaction.commit and DBTransaction.rollback. #56

Open
CMCDragonkai opened this issue Aug 22, 2022 · 0 comments
Labels
development Standard development r&d:polykey:supporting activity Supporting core activity

Comments

@CMCDragonkai
Copy link
Member

Specification

Previously the destroy call was called inside commit and rollback. This has since been removed since #53, since the ResourceAcquire<DBTransaction> already called destroy and it was unnecessary to call destroy 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 a TRANSACTION_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 the get 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 make destroy have a type: 'commit' | 'rollback' union. This way DBTransaction.commit and DBTransaction.rollback is just forwarding the call to the destroy.

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

Tasks

  1. ...
  2. ...
  3. ...
@CMCDragonkai CMCDragonkai added the development Standard development label Aug 22, 2022
@CMCDragonkai CMCDragonkai self-assigned this Jul 10, 2023
@CMCDragonkai CMCDragonkai added the r&d:polykey:supporting activity Supporting core activity label Jul 10, 2023
@CMCDragonkai CMCDragonkai removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development r&d:polykey:supporting activity Supporting core activity
Development

No branches or pull requests

1 participant