Skip to content

IDBMirrorVFS: wait for IndexedDB transactions to finish in close() - #385

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

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

Conversation

@lalexdotcom

Copy link
Copy Markdown
Contributor

What happens

IDBMirrorVFS.close() closes its IDBDatabase and returns without waiting for transactions still in flight. jClose() already waits for commits (commitsInFlight), but the other transactions are awaited on their requests only. For example, jOpen() checks and loads the file in a readwrite transaction that can still be live after sqlite3.close(db) and vfs.close(), even when nothing was written.

No data is lost in Chrome and Firefox. 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). Terminating the worker is the usual reason to close.

That Safari bug is the only consequence I found. WebKit has fixed it, but so far only in Safari Technology Preview: Safari 27.0.1 still has it, and so do earlier versions, iOS included. Once the Safari versions in use carry the fix, this change no longer has any effect I know of.

The change

Every transaction goes through a private #transaction(), which tracks it until complete or abort. close() closes the database, then waits for those transactions; a transaction already started runs to completion after IDBDatabase.close(). VFS.Base.close() already allows a promise.

The cost: close() resolves after the last transaction finishes instead of before it.

The test

test/vfs_close_settles.js, run by IDBMirrorVFS.test.js for both builds: on the page, with IDBDatabase.prototype.transaction wrapped to count transactions until complete or abort. Five times, a database is created and written, then reopened and read, and after each vfs.close() no transaction may be live. It fails on master in Chrome and Firefox, for both builds, and passes with the change.

Relation to #384

#384 makes the same change in IDBBatchAtomicVFS, where the live transaction can also lose a commit. The two PRs touch different files.

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 6633680 into rhashimoto:master Oct 23, 2026
1 check passed
@lalexdotcom
lalexdotcom deleted the idbmirror-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