Repository navigation
IDBBatchAtomicVFS: wait for IndexedDB transactions to finish in close() - #384
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 21, 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
IDBBatchAtomicVFS.close()closes itsIDBDatabaseand returns without waiting for transactions still in flight. WithPRAGMA synchronous=normal,jClose()callssync(false). That waits for the requests to be made but not for the last transaction to commit, andreset()then forgets that transaction. So aftersqlite3.close(db)andvfs.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 afterjAccess(). In Safari, ending a worker before its last transaction completes can leave its connection open, andindexedDB.deleteDatabase()and version upgrades then block (WebKit bug 324094).The lost commit reproduces in Chrome and Firefox, most reliably in Firefox.
The change
IDBContexttracks every transaction it starts untilcompleteorabort, in a set thatreset()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=normalstill does not wait for a commit beforexSync()returns.The test
test/vfs_commit_survives.jsgets a third case: a worker inserts a row withsynchronous=normal, closes the database and the VFS, answers, and is terminated. That runs 10 times, then a new worker counts the rows. It fails onmasterin Chrome and Firefox, for both builds, and passes with the change.IDBMirrorVFSmay have a similar problem and is being looked into separately.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.