Repository navigation
OPFSCoopSyncVFS: retry access handles still held after a terminated connection - #381
Merged
rhashimoto merged 5 commits intoOct 23, 2026
Merged
Conversation
…onnection A connection whose worker is terminated mid-call releases its Web Lock at once and its access handles only later. The connection granted the lock next then failed createSyncAccessHandle() with NoModificationAllowedError (InvalidStateError in WebKit), which left the SQLite call as a raw exception. Creating the handles is now retried for up to a second while the lock is held. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…roy() The test needs a worker terminated with no chance to close its VFS; a destroy() that closes it first would no longer reproduce the race. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a slow engine a round that failed could outlast the test's timeout and keep its workers running into the next test, which then met files still held. Each round now waits a bounded time and cleans up in a finally; the test takes the suite's timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measured: a worker terminated inside a JavaScript loop kept its file for up to 956 ms on Firefox on Windows; 1 s left no margin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
lalexdotcom
added a commit
to lalexdotcom/browser-sqlite
that referenced
this pull request
Oct 16, 2026
A worker terminated while it holds OPFS sync access handles frees its Web Lock before its files, on every engine. OPFSCoopSyncVFS hands its handle over through that lock and called createSyncAccessHandle() once, so the next holder's statement failed with a raw DOM error that reaches the caller with no SQLiteError code. The library terminates a worker that misses its open timeout, so a client sharing the database could meet it. Carried as a pnpm patch until rhashimoto/wa-sqlite#381 merges: its src/ hunks only, byte for byte the PR head 3c75a3c8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 16, 2026
2 tasks done
rhashimoto
requested changes
Oct 23, 2026
rhashimoto
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR!
Just a couple code polishing suggestions.
2 tasks done
Each access handle the attempt gets registers its own undo, so a retry no longer fetches every related file to test what it holds. The type guard on the search keeps TypeScript before 5.5, which does not infer it, from reporting failure.reason as an error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Thanks for the review! Both are done in 42bfb90:
The full suite still passes on Chrome, and |
Owner
I figured that was the case. I use Yarn PnP, which TS 7 doesn't support. I'll try with TS 5.5, though, thanks for that! |
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
When a connection's worker is terminated in the middle of a call, the browser releases its Web Lock at once but its access handles only some time later. The connection queued on that lock is granted it, calls
createSyncAccessHandle(), and getsNoModificationAllowedError(InvalidStateErrorin WebKit) because the file is still held.#requestAccessHandle()rethrows it, andretry()lets it out of the SQLite call as a raw exception: the statement fails with a DOM error and no SQLite result code.This reproduces in Chrome, Firefox and Safari, most reliably in Firefox, which takes longer to release the file, especially on Windows.
The change
Once
#requestAccessHandle()holds the lock, aNoModificationAllowedErrororInvalidStateErrorfromcreateSyncAccessHandle()is retried: the handles that attempt got are closed, the lock is kept, and the attempt is repeated every 10 ms for up to 5 s, well above the time the browsers take to release the file. Any other error is thrown at once, as before.The cost: a file held outside the lock protocol (for example by another page's handle that never lets go) now fails after 5 s instead of immediately. The open path still reports it as
SQLITE_CANTOPENwith the samelastError.OPFSAdaptiveVFSuses the same lock-and-notify hand-over wherereadwrite-unsafeis not available and may have the same problem; we are looking into it separately.Test
test/vfs_handover.jsgains a test: connection B opens a database, connection A opens it and starts a long query, B starts a query and queues on the lock, then A's worker is terminated directly, so the test does not depend on whatTestContext.destroy()does first. It runs 10 rounds per build, each bounded and cleaned up so a failure cannot spill into the next test.On
master, B's query fails with the rawNoModificationAllowedError/InvalidStateErrorin Chrome, Firefox (Linux and Windows) and Safari 26 and 27, on every build where the race came up. With the change,OPFSCoopSyncVFS.test.jspasses on all of them, and the whole suite passes on Chrome.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.