Skip to content

About

Standalone reproduction of TanStack DB OPFS worker lifecycle and wa-sqlite access handle failures

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TanStack DB / wa-sqlite OPFS reproduction

A standalone reproduction of OPFS initialization and page-lifecycle failures. No backend, UI framework, collections, authentication, application code, or package patches are required. The default install uses published packages:

TanStack embeds its own VFS in a prebuilt worker. Replacing the peer dependency in an application's install does not replace that embedded VFS. This repo tests the public opener, the shipped worker, and the standalone VFS separately.

Run the published-version reproduction

Requires Bun (tested with 1.4.2) and a Chromium browser with OPFS support.

git clone https://github.com/zhy0216/tanstack-opfs-repro.git
cd tanstack-opfs-repro
bun install --frozen-lockfile
bun run start

Open http://127.0.0.1:4173 in Chrome and click a scenario. Each run uses a new, random database name and terminates its test workers afterward. Use a separate browser profile for testing; the standalone VFS performs its usual temporary-file cleanup within this localhost origin.

For automated assertions:

bunx playwright install chromium
bun run repro

Alternatively set CHROME_PATH to an installed Chrome executable. The repro command exits successfully when it observes the unfixed behavior, including the leaked native handle. It writes results/baseline.json.

Scenarios and observed behavior

Scenario Published packages With both source fixes
pagehide-initializing Worker survives pagehide; initialization can subsequently succeed Worker terminated synchronously; opening rejects with AbortError
pagehide-ready Worker survives; native DB/journal handles remain unavailable Worker terminated; another worker can acquire native handles
tanstack-transient One failed attempt, sqlite3_open_v2, partial handles remain held Retries and opens after WAL holder releases
tanstack-persistent Generic error, partial handles remain held Bounded retries, native error name + WAL filename, partial handles closed
tanstack-wrong-type Generic sqlite3_open_v2 TypeMismatchError included, no contention retry
vfs-transient Open fails after one attempt Open succeeds; a marker survives close/reopen
vfs-persistent Late journal handle leaks, lastError is null Stops after about 3 seconds; handles closed; cause retained
vfs-non-retryable Partial handles leak; cause discarded One attempt, handles closed, NotAllowedError retained
vfs-wrong-type lastError is null TypeMismatchError retained

The lifecycle cases dispatch a synthetic pagehide event with persisted: true. They verify the handler's behavior with a real worker and real OPFS. They do not claim that a real navigation entered the back/forward cache. A cached document must reopen its connections after pageshow; cleanup does not flush pending writes.

The contention cases deliberately hold a real WAL sync access handle without taking the cooperative Web Lock. This isolates native-handle contention from Web Lock contention. The holder releases 150 ms after the first conflict in the transient case and stays open throughout the persistent case.

To make the cleanup race repeatable, the worker delays delivery of a successfully acquired journal handle by 75 ms. The actual native acquisition is not mocked. The failing database worker is kept alive while another handle is requested; terminating it first would hide the leak. Only vfs-non-retryable injects an error (NotAllowedError) to check that unrelated failures are not retried.

The smallest relevant files are browser.js (public opener and worker-protocol calls), server.js (bundled-worker instrumentation), and vfs-worker.js (standalone VFS test).

Verify the source fixes together

Upstream pull requests:

Source branches:

Check out both branches and install their dependencies using the upstream instructions. TanStack currently requires Node 24.8.0 and pnpm 11.1.0. If only the relevant packages are needed, run this in the TanStack checkout:

corepack pnpm install --frozen-lockfile --filter @tanstack/browser-db-sqlite-persistence... --filter root

Then run in this reproduction repo (use absolute paths):

export TANSTACK_REPO=/absolute/path/to/db
export WASQLITE_DIR=/absolute/path/to/wa-sqlite
node build-fixed.js
export TANSTACK_PACKAGE_DIR="$TANSTACK_REPO/packages/browser-db-sqlite-persistence"
bun run verify:fixed

build-fixed.js builds the four relevant TanStack packages. For the browser package only, it resolves OPFSCoopSyncVFS.js to the wa-sqlite source checkout, so the worker really contains the fix. It does not edit node_modules, apply a package patch, change dependency manifests, or vendor the VFS into TanStack. This is a local integration check, not a proposal to change TanStack's peer dependency to wa-sqlite 2.x. A release/backport and a worker rebuild are needed for downstream consumers to receive the VFS fix.

verify:fixed asserts the corrected behavior and writes results/fixed.json. Unset TANSTACK_PACKAGE_DIR and WASQLITE_DIR to test published packages again.

Recorded results

Tested on macOS arm64 / Chrome 153.0.8010.48. All nine expected baseline scenarios and all nine corrected scenarios passed their respective assertions.

Source bases: TanStack DB 09776a892c73f4abd593d1eda4914cdbc20451b3 and wa-sqlite cff99da177ec6d99f2a54c9b4fbbfef7f827d90f. Fix commits: TanStack DB a31b0fa0c806c799781cc41964cc89374a2a106c and wa-sqlite 5d5863f.

About

Standalone reproduction of TanStack DB OPFS worker lifecycle and wa-sqlite access handle failures

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages