Repository navigation
OPFSAdaptiveVFS: retry a held access handle after a terminated connection - #382
Merged
rhashimoto merged 1 commit intoOct 23, 2026
Merged
Conversation
…tion Without readwrite-unsafe access handles, a connection whose worker is terminated mid-call releases its Web Lock at once and its access handle only later. The connection granted the lock next then failed createSyncAccessHandle() in jLock() with NoModificationAllowedError (InvalidStateError in WebKit): the exception left the SQLite call raw, and the connection kept the lock with no handle, which left every other connection waiting on it. Creating the handle is now retried for up to 5 s while the lock is held; on failure the lock is given back and jLock() returns SQLITE_IOERR_LOCK. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 tasks done
rhashimoto
approved these changes
Oct 23, 2026
rhashimoto
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR! LGTM, but I'm going to wait until you're done with #381 to merge in case you see anything while you're making changes there that might also apply here.
2 tasks done
Contributor
Author
|
I went over #381's review for this one. Here the access handle is a single acquisition in a |
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
On platforms without
readwrite-unsafeaccess handles (Firefox and Safari),OPFSAdaptiveVFShands its access handle between connections through a Web Lock. When a connection's worker is terminated while it holds the handle, the browser releases the lock at once but the access handle only later. The connection granted the lock next then getsNoModificationAllowedError(InvalidStateErrorin WebKit) fromcreateSyncAccessHandle()injLock(), which has notry. The exception leaves the SQLite call raw, and the connection keeps the lock with no handle: with the asyncify build its query never settles and every other connection waits on the lock; with JSPI the query fails, the next one returnsSQLITE_IOERR, andclose()never returns.This reproduces in Firefox, most reliably on Windows.
The change
Once
jLock()holds the lock, aNoModificationAllowedErrororInvalidStateErrorfromcreateSyncAccessHandle()is retried every 10 ms for up to 5 s. Any other error, or the deadline, gives the lock back and returnsSQLITE_IOERR_LOCK, so a connection never holds the lock without the handle.The cost: a file held outside the lock protocol now makes
jLock()fail after 5 s instead of immediately.The test
test/vfs_terminated_holder.js, run forOPFSAdaptiveVFS: 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. It runs 10 rounds per build, each bounded and cleaned up so a failure cannot spill into the next test.It fails on
masterin Firefox and passes with the change. It cannot fail in Chrome, which hasreadwrite-unsafeand never takes this path, so CI here does not exercise it. In Safari it did not reproduce: a worker running in WebAssembly is not terminated there until it yields.Relation to #381
This is the
OPFSAdaptiveVFSside of #381, which said this VFS was being looked into. Both VFS hand their access handle over through a Web Lock (here only withoutreadwrite-unsafe), so both meet the same race: a terminated holder releases the lock before its handle. The change is the same: once the lock is held, retrycreateSyncAccessHandle()onNoModificationAllowedErrororInvalidStateError, every 10 ms for up to 5 s, with the same constant names. The test is the same shape too. There are two differences:OPFSCoopSyncVFSthe failed hand-over only failed the statement. Here, the connection also kept the lock without a handle, which stalls every other connection. So on failure this change also gives the lock back, and returnsSQLITE_IOERR_LOCKwhereOPFSCoopSyncVFSrethrows from its retry operation.OPFSCoopSyncVFShands over everywhere, so OPFSCoopSyncVFS: retry access handles still held after a terminated connection #381 reproduces in Chrome too.OPFSAdaptiveVFStakes this path only in Firefox and Safari, so this test cannot fail in Chrome or in CI here.The two tests do not touch the same lines: #381's is in
test/vfs_handover.js, this one in its own file. Whichever merges second, I can move both onto one shared helper if you prefer.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.