Fail closed when the wasm wallet database can't persist to OPFS#1046
Open
jamaljsr wants to merge 2 commits into
Open
Fail closed when the wasm wallet database can't persist to OPFS#1046jamaljsr wants to merge 2 commits into
jamaljsr wants to merge 2 commits into
Conversation
A second browser tab cannot acquire the wallet database's exclusive OPFS handles, and the SQLite worker used to degrade that open failure to an in-memory database. The daemon then booted against a throwaway store and died much later inside migrations with an unrelated-looking SQLITE_CANTOPEN, while any writes that had succeeded were doomed to vanish on page close (issue wavelength-sdk#48). Set require_persistent on the DSN so the open fails closed with the real locked-database error instead. Widen the open retry predicate to SQLITE_BUSY, which is how lock contention now surfaces: the retries still absorb the brief handle-release race after a reload, and a lock holder that never goes away exhausts them and returns the locked error to the caller, where the SDK maps it to a typed wallet_locked failure.
Mirror the db store's fail-closed behavior for btcwallet's OPFS-backed walletdb: never fall back to an in-memory database when the persistent OPFS VFS cannot be opened, and treat SQLITE_BUSY as retryable alongside SQLITE_CANTOPEN, since lock contention now surfaces as an open failure rather than a silent in-memory downgrade.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Member
Author
|
Complemented by the SDK-side fast-path guard in lightninglabs/wavelength-sdk#56, which detects the second tab via a Web Lock before it reaches this daemon path. |
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
A second browser tab can't acquire the wallet database's exclusive OPFS handles, and the wasm SQLite worker used to treat that open failure as a cue to fall back to an in-memory database. The daemon then booted against a throwaway store and died much later inside migrations with an unrelated-looking
SQLITE_CANTOPEN, while any writes that had already succeeded were doomed to vanish on page close. That's the raw trace behind lightninglabs/wavelength-sdk#48.This makes the open fail closed instead:
require_persistenton the DSN turns a missing persistent OPFS VFS into a real locked-database error at open time, so there's no silent in-memory downgrade and no confusing failure later in migrations.Changes
require_persistent=trueon both wasm SQLite DSNs: the generic db store (db/sqlite_open_wasm.go) and btcwallet's OPFS-backed walletdb (lwwallet/walletdb_wasm.go).SQLITE_BUSYanddatabase is lockedalongside the existingSQLITE_CANTOPEN, since contention now surfaces as an open failure rather than an in-memory fallback. The helpers are renamedisWASM*RetryableOpento match.wallet_locked.Testing
Related
wallet_lockedmapping, and will cross-link here once it's open.