Skip to content

Wait loop questions #436

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

Open
stelar7 opened this issue Jan 1, 2025 · 4 comments · Fixed by #447
Open

Wait loop questions #436

stelar7 opened this issue Jan 1, 2025 · 4 comments · Fixed by #447
Labels

Comments

@stelar7
Copy link

stelar7 commented Jan 1, 2025

In Upgrading a database step 11 is supposed to wait for the transaction to finish.

A transaction is finished once it enters the finished state (after commit or abort)

Calling indexedDB.open("test", 1) will cause an upgrade, and then step 10.5 could change the state (via autocommit, or user action), but then we instantly set it back to inactive in step 10.6

  • Should step 11 instead be waiting for the task created in step 10 to finish? Or am I missing something here?

Given the following snippet:

let db;
const open_rq = indexedDB.open(undefined, 9);

open_rq.onupgradeneeded = function (e) {
    db = e.target.result;
};
    
open_rq.onsuccess = function (e) {
    db.close();
    let open_rq2 = indexedDB.open(db.name, 10);
};

Once we get to close a database connection step 3. we will be stuck in an infinite loop, because at no point has the transaction gone to the finished state. (The onupgradeneeded callback does nothing that would cause an abort or commit)

  • Is there a spec step im missing that handles this case?
@stelar7 stelar7 changed the title Database upgrade loop question Database upgrade wait loop question Jan 1, 2025
@stelar7 stelar7 changed the title Database upgrade wait loop question Wait loop questions Jan 1, 2025
@inexorabletash
Copy link
Member

During the firing the version change event (10.5), script may make additional requests. These would keep the transaction alive, so going inactive at 10.6 would not cause the transaction to auto-commit. So waiting for the transaction to finish in step 11 is intentional.

In the case where no requests are made (e.g. your code example), the relevant prose is in the transaction lifetime definition: "The implementation must attempt to commit a transaction when all requests placed against the transaction have completed and their returned results handled, no new requests have been placed against the transaction, and the transaction has not been aborted" The intention is that once we reach a state where all existing requests are completed and new requests can be made, the transaction should attempt to commit.

The statement could be made more explicit e.g. by stating "The implementation must attempt to commit a transaction when it is inactive, all requests..."

Making the whole transaction lifecycle more algorithmic would also be nice. :)

@stelar7
Copy link
Author

stelar7 commented Apr 9, 2025

@inexorabletash
Another question here:

10.5 can set the state to finished (by aborting) as in the example below.
step 10.6 then sets it back to Inactive.
At this point, we havent thrown, so 10.7 does nothing.
Since the transaction has been aborted, it is not possible to auto-commit it any more.

Are we now stuck in an infinite loop at step 11?
Is step 10.6 and 10.7 only supposed to run if we are not put into the finished state by the event?

    async_test(function (t) {
        let rq = indexedDB.open();
        rq.onupgradeneeded = t.step_func(function () {
            rq.transaction.abort();
        });
        rq.onerror = t.step_func(function () {
            t.done()
        });
}

@inexorabletash
Copy link
Member

Is step 10.6 and 10.7 only supposed to run if we are not put into the finished state by the event?

Yep.

We should add a step after step 10.5 that's basically "If transaction's state is active, then run these steps:" and make the subsequent steps substeps of this. I believe that will handle calling either abort() or commit() during the dispatch, similar to https://w3c.github.io/IndexedDB/#fire-a-success-event

inexorabletash added a commit that referenced this issue Apr 11, 2025
* Clarify that only inactive transactions should auto-commit.

* Fix upgrade steps to correctly handle aborted transactions.

Resolves #436
inexorabletash added a commit that referenced this issue Apr 11, 2025
* Clarify that only inactive transactions should auto-commit.

* Fix upgrade steps to correctly handle aborted transactions.

Resolves #436
@inexorabletash
Copy link
Member

Re-opening, as it would still be nice to have more explicit lifecycle steps for transactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants