Conversation
…ce condition (0xMiden#287) - Synchronize openDatabase calls per network using Web Locks API (navigator.locks) with an in-process queue fallback - Prevents concurrent store resets and DatabaseClosedError when WebClient initializes on main thread and web worker simultaneously - Add concurrent openDatabase and version reset race tests
Lesnak1
force-pushed
the
fix/idxdb-store-init-race-condition
branch
from
September 1, 2026 11:11
f124e48 to
5977bab
Compare
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.
Summary
Fixes #287.
Initializing
WebClientwith the defaultuseWorker: truestarts WASM both on the main thread and in the web worker, callingopenDatabase(storeName, clientVersion)concurrently against the same database.When
ensureClientVersiontriggers a reset path (e.g. major/minor version mismatch or invalid semver),dexie.delete()emits aversionchangeevent that closes the peer connection. Whichever thread reachesdelete()second deletes the freshly reopened database while settings reads/writes are in flight, rejecting withDatabaseClosedErrorand throwingFailed to initialize IdxdbStore.Changes
crates/idxdb-store/src/ts/schema.ts):acquireDbInitLockwrappingopenDatabaseusing the standard Web Locks API (navigator.locks.request("miden-db-init:${name}", ...)).navigator.locks.getStoredClientVersion(), recognizes the version matches, and proceeds without closing or re-deleting the database.crates/idxdb-store/src/js/schema.js.crates/idxdb-store/src/ts/schema.test.tsasserting concurrentopenDatabasecalls during a major version reset complete cleanly without errors or dangling connections.navigator.locksintegration when present.Verification
crates/idxdb-storepass cleanly (vitest run).eslint --fix,prettier --write) passed.