Skip to content

fix(wa-sqlite): recover cleanly from OPFS initialization failure - #208

Merged
Antonov548 merged 1 commit into
stack/wa-sqlite-explicit-initfrom
fix/wa-sqlite-opfs-init-fallback
Aug 5, 2026
Merged

fix(wa-sqlite): recover cleanly from OPFS initialization failure#208
Antonov548 merged 1 commit into
stack/wa-sqlite-explicit-initfrom
fix/wa-sqlite-opfs-init-fallback

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

#210 prevents the reproduced automatic-extension failure, but any remaining OPFS initialization error still has to unwind every layer cleanly. A failed attempt can leave behind a database handle, VFS resources, wa-sqlite module callbacks/retry state, worker listeners, pending RPC calls, or an attached SharedWorker port.

In SharedWorker mode, that stale port can keep a failed session alive and make the next client using the same worker name fail as if a different database were already initialized.

Change

  • Close partially initialized database and VFS resources idempotently.
  • Run optional memory fallback in a fresh wa-sqlite module. Closing the failed VFS does not unregister its callbacks or reset module retry state, so reusing that module is unsafe.
  • Preserve both the OPFS error and the fallback error when both attempts fail.
  • Remove listeners, reject pending RPC calls, close ports, and terminate dedicated workers when initialization, close, or drop fails.
  • Cover recovery by forcing an OPFS open failure and then successfully reusing the same SharedWorker name.

This PR is the cleanup and recovery layer after #210; it does not claim to be the root fix for the initialization failure.

Dependencies and merge order

Stacked directly on #210. Use a merge commit after #210, then retarget #163 to main.

@marcus-pousette marcus-pousette added bug Something isn't working area:sqlite SQLite extension, sqlite-node, wa-sqlite persistence, and migrations area:web Browser, WASM, OPFS, workers, and playground runtime labels Jul 12, 2026
@marcus-pousette
marcus-pousette force-pushed the fix/wa-sqlite-opfs-init-fallback branch 2 times, most recently from ed2a220 to f57f74c Compare July 14, 2026 20:36
@marcus-pousette
marcus-pousette force-pushed the fix/wa-sqlite-opfs-init-fallback branch 2 times, most recently from f36e6d7 to 7f7b5e3 Compare July 15, 2026 07:16
@marcus-pousette
marcus-pousette changed the base branch from main to stack/wa-sqlite-explicit-init July 15, 2026 07:16
@marcus-pousette
marcus-pousette force-pushed the fix/wa-sqlite-opfs-init-fallback branch from 7f7b5e3 to b10857c Compare July 15, 2026 08:01
@marcus-pousette
marcus-pousette force-pushed the stack/wa-sqlite-explicit-init branch from c3b9927 to 4401d00 Compare July 15, 2026 08:01
@marcus-pousette
marcus-pousette force-pushed the fix/wa-sqlite-opfs-init-fallback branch from b10857c to 853fa52 Compare July 16, 2026 09:52
@marcus-pousette
marcus-pousette force-pushed the stack/wa-sqlite-explicit-init branch from 4401d00 to 1952830 Compare July 16, 2026 09:52
@Antonov548
Antonov548 merged commit 00e8024 into stack/wa-sqlite-explicit-init Aug 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sqlite SQLite extension, sqlite-node, wa-sqlite persistence, and migrations area:web Browser, WASM, OPFS, workers, and playground runtime bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants