Clear retryOps on error #59
Merged
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.
Overview
When an async operation pushed to
Module.retryOpsrejects, the rejected promise remains in the array indefinitely. This causes all subsequent SQLite operations to fail immediately, effectively breaking the database connection until a page refresh.Root Cause
The
retry()function insqlite-api.jsawaits all pending retry operations before retrying a SQLite call. Previously, the array was only cleared after a successfulPromise.all():If any promise rejects,
Promise.all()throws andModule.retryOps = []is never executed.Example Scenario
xOpenpushes an async operation toretryOps(e.g., acquiring a file access handle)createSyncAccessHandle()throws due to the file being locked by another tab)Promise.all(Module.retryOps)rejectsModule.retryOpsretry()Promise.all(Module.retryOps)which contains the already-rejected promiseThe connection is now permanently broken—even unrelated operations that would otherwise succeed will fail.
Fix
Use a
finallyblock to ensureretryOpsis always cleared, regardless of whether the promises resolve or reject:This ensures each retry iteration starts with a clean state. The original error still propagates to the caller (as expected), but future operations are not blocked by stale rejected promises.
How retries work
The
retryOpsmechanism works as follows:SQLITE_BUSYretry()awaits all pending ops, then retries the synchronous callEach iteration should operate on a fresh set of promises. Rejected promises from a failed attempt have no bearing on subsequent attempts—the VFS will push new promises as needed.