Repository navigation
IDBMirrorVFS: wait for IndexedDB transactions to finish in close() - #385
Merged
rhashimoto merged 2 commits intoOct 23, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happens
IDBMirrorVFS.close()closes itsIDBDatabaseand 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 aftersqlite3.close(db)andvfs.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 untilcompleteorabort.close()closes the database, then waits for those transactions; a transaction already started runs to completion afterIDBDatabase.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 byIDBMirrorVFS.test.jsfor both builds: on the page, withIDBDatabase.prototype.transactionwrapped to count transactions untilcompleteorabort. Five times, a database is created and written, then reopened and read, and after eachvfs.close()no transaction may be live. It fails onmasterin 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
non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
derivative works of, publicly display, sublicense, and distribute this
Contribution and such derivative works.
Contribution contains no content requiring a license from any third party.