Repository navigation
IDBMirrorVFS: recover from a commit whose IndexedDB transaction aborts #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rhashimoto
merged 5 commits into
rhashimoto:master
from
lalexdotcom:fix/idb-mirror-commit-abort
Oct 10, 2026
+382
−60
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1844c76
Recover IDBMirrorVFS from a commit whose IndexedDB transaction aborts.
lalexdotcom 1f7b253
Add IDBMirrorVFS tests for a commit whose IndexedDB transaction aborts.
lalexdotcom 3367cb6
Reload the IDBMirrorVFS view when a commit is refused.
lalexdotcom 874303e
Make IDBMirrorVFS's commit write path sequential, per review.
lalexdotcom cb97dee
IDBMirrorVFS: abort the commit transaction if its write body throws
lalexdotcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // A worker for vfs_commit_abort.js, holding one connection on | ||
| // IDBMirrorVFS. It can make the next IndexedDB commit abort, as a full | ||
| // quota would, optionally after keeping the transaction alive. | ||
| import * as SQLite from '../src/sqlite-api.js'; | ||
| import { IDBMirrorVFS } from '../src/examples/IDBMirrorVFS.js'; | ||
|
|
||
| const BUILDS = new Map([ | ||
| ['default', '../dist/wa-sqlite.mjs'], | ||
| ['asyncify', '../dist/wa-sqlite-async.mjs'], | ||
| ['jspi', '../dist/wa-sqlite-jspi.mjs'], | ||
| ]); | ||
|
|
||
| const searchParams = new URLSearchParams(location.search); | ||
|
|
||
| let abortNextCommit = false; | ||
| let abortDelay = 0; | ||
| const commit = IDBTransaction.prototype.commit; | ||
| IDBTransaction.prototype.commit = function() { | ||
| if (abortNextCommit && this.mode === 'readwrite') { | ||
| abortNextCommit = false; | ||
| if (!abortDelay) return this.abort(); | ||
|
|
||
| // Keep the transaction active with requests, then abort it. | ||
| const deadline = Date.now() + abortDelay; | ||
| const store = this.objectStore('tx'); | ||
| const keepAlive = () => { | ||
| if (Date.now() < deadline) { | ||
| store.get(['', 0]).onsuccess = keepAlive; | ||
| } else { | ||
| this.abort(); | ||
| } | ||
| }; | ||
| return keepAlive(); | ||
| } | ||
| return commit.call(this); | ||
| }; | ||
|
|
||
| const ready = (async () => { | ||
| const { default: moduleFactory } = await import(BUILDS.get(searchParams.get('build'))); | ||
| const module = await moduleFactory(); | ||
| const sqlite3 = SQLite.Factory(module); | ||
| const vfs = await IDBMirrorVFS.create(searchParams.get('idb'), module); | ||
| sqlite3.vfs_register(vfs, true); | ||
| return { sqlite3, db: await sqlite3.open_v2('commit-abort') }; | ||
| })(); | ||
|
|
||
| // A read-only transaction completes after the read-write transactions | ||
| // created before it, and after their completion or abort events. Closing | ||
| // before a commit completes makes its broadcast throw, which is not what | ||
| // these tests are about. | ||
| async function commitsFinished() { | ||
| const idb = await new Promise((resolve, reject) => { | ||
| const request = indexedDB.open(searchParams.get('idb')); | ||
| request.onsuccess = () => resolve(request.result); | ||
| request.onerror = () => reject(request.error); | ||
| }); | ||
| await new Promise(resolve => { | ||
| const tx = idb.transaction(['blocks', 'tx']); | ||
| tx.objectStore('tx').count(); | ||
| tx.oncomplete = tx.onabort = resolve; | ||
| }); | ||
| idb.close(); | ||
| } | ||
|
|
||
| addEventListener('message', async ({ data }) => { | ||
| try { | ||
| const state = await ready; | ||
| const { sqlite3 } = state; | ||
| switch (data.type) { | ||
| case 'exec': { | ||
| const rows = []; | ||
| try { | ||
| await sqlite3.exec(state.db, data.sql, row => rows.push(row)); | ||
| postMessage({ rows }); | ||
| } catch (e) { | ||
| postMessage({ rows, error: e.message }); | ||
| } | ||
| break; | ||
| } | ||
| case 'abort-next-commit': | ||
| abortNextCommit = true; | ||
| abortDelay = data.delay ?? 0; | ||
| postMessage({}); | ||
| break; | ||
| case 'sleep': | ||
| await new Promise(resolve => setTimeout(resolve, data.ms)); | ||
| postMessage({}); | ||
| break; | ||
| case 'settle': | ||
| await commitsFinished(); | ||
| postMessage({}); | ||
| break; | ||
| case 'reopen': | ||
| await commitsFinished(); | ||
| await sqlite3.close(state.db); | ||
| state.db = await sqlite3.open_v2('commit-abort'); | ||
| postMessage({}); | ||
| break; | ||
| case 'close': | ||
| await commitsFinished(); | ||
| await sqlite3.close(state.db); | ||
| postMessage({}); | ||
| break; | ||
| } | ||
| } catch (e) { | ||
| postMessage({ error: e.message }); | ||
| } | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.