Skip to content

IDBBatchAtomicVFS: wait for IndexedDB transactions to finish in close() - #384

Merged
rhashimoto merged 2 commits into
rhashimoto:masterfrom
lalexdotcom:idbbatchatomic-close-settle
Oct 23, 2026
Merged

rhashimoto merged 2 commits into
rhashimoto:masterfrom
lalexdotcom:idbbatchatomic-close-settle

Conversation

@lalexdotcom

Copy link
Copy Markdown
Contributor

What happens

IDBBatchAtomicVFS.close() closes its IDBDatabase and returns without waiting for transactions still in flight. With PRAGMA synchronous=normal, jClose() calls sync(false). That waits for the requests to be made but not for the last transaction to commit, and reset() then forgets that transaction. So after sqlite3.close(db) and vfs.close() the last commit can still be pending. If the worker is terminated right after, which is the usual reason to close, that commit is lost.

A readonly transaction can also still be live when close() returns, for example after jAccess(). In Safari, ending a worker before its last transaction completes can leave its connection open, and indexedDB.deleteDatabase() and version upgrades then block (WebKit bug 324094).

The lost commit reproduces in Chrome and Firefox, most reliably in Firefox.

The change

IDBContext tracks every transaction it starts until complete or abort, in a set that reset() does not clear. close() lets the queued calls make their requests, closes the database, then waits for those transactions. IDBBatchAtomicVFS.close() returns that promise; VFS.Base.close() already allows one.

The cost: close() now resolves after the last commit instead of before it. Nothing else changes; synchronous=normal still does not wait for a commit before xSync() returns.

The test

test/vfs_commit_survives.js gets a third case: a worker inserts a row with synchronous=normal, closes the database and the VFS, answers, and is terminated. That runs 10 times, then a new worker counts the rows. It fails on master in Chrome and Firefox, for both builds, and passes with the change.

IDBMirrorVFS may have a similar problem and is being looked into separately.

Checklist

  • I grant to recipients of this Project distribution a perpetual,
    non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
    derivative works of, publicly display, sublicense, and distribute this
    Contribution and such derivative works.
  • I certify that I am legally entitled to grant this license, and that this
    Contribution contains no content requiring a license from any third party.

@rhashimoto rhashimoto left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! LGTM.

@rhashimoto
rhashimoto merged commit ced5652 into rhashimoto:master Oct 23, 2026
1 check passed
@lalexdotcom
lalexdotcom deleted the idbbatchatomic-close-settle branch October 26, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants