Worker: init() rejection is never propagated to clients
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- api
Research direction
Start in worker/index.ts: the postMessage({ type: "ready", id }) that precedes dbPromise = init(options), the tab-here retry handler that re-awaits dbPromise, and connectTab. Trace PGliteWorkerClientApi.create() and waitReady on the main thread to see why only the connected message settles them. Done means a rejected init() rejects create() and pending/future waitReady with the original error, the 16 ms retry loop stops, and repeated tab-here retries no longer produce unhandled rejections — verify with the issue's fault-injection repro (no OPFS needed).
Written by the indexing model from the issue text.
Description
Version
@electric-sql/pglite 0.5.8 (@electric-sql/pglite/worker, Multi-Tab Worker)
Summary
When the worker-side init() callback rejects, the failure is never propagated to the main-thread client. Three consequences, all observed with fault injection (a plain init: async () => { throw new DOMException(..., "InvalidStateError") } — no OPFS required):
PGliteWorkerClientApi.create()resolves anyway — it only awaits thereadyack, whichworker()posts before running init (worker/index.ts:postMessage({ type: "ready", id })precedesdbPromise = init(options)).waitReadypends forever — it resolves only on theconnectedmessage, whichconnectTabposts only afterawait dbPromisesucceeds. With a rejected init it neither resolves nor rejects: any application awaitingwaitReadybefore its first query hangs silently, with zero errors and no teardown signal.- The failure is amplified into an unhandled-rejection storm — the client retries
tab-hereevery 16 ms untilconnected; the leader-side handler (case "tab-here": connectTab(id, await dbPromise, …)) re-awaits the same rejected promise on every retry, so each retry is an unhandled rejection in the worker. Measured in a consumer application's fault-injection run: 4,500 uncaughtInvalidStateErrorin 40 s (~110/s), with thousands more dropped by the console buffer.
Minimal repro
// worker
await worker({
init: async (options) => {
throw new DOMException("boom", "InvalidStateError");
},
});
// main thread
const db = await PGliteWorker.create(worker, { dataDir: "opfs-ahp://demo" }); // resolves!
await db.waitReady; // pends forever; meanwhile the worker console floods
Expected
A rejected init() should reject create() (and any pending or future waitReady) with the original error, stop the tab-here retry loop, and fail later tabs' handshakes with the stored init error instead of re-raising it per retry.
Also observed (same code path, adjacent)
The main-thread retry timer keeps firing after client close() (it doesn't observe closure), so closing the BroadcastChannels turns the silent loop into InvalidStateError: postMessage on closed Channel thrown inside a timer callback. Either the timer should observe closed, or close() docs should warn that channels must remain open until unload.
Related
- #1064 — async-executor never-settle in opfs-ahp pool init (the other half of "broken startup wedges silently")
- #1109 — rpc with no leader hangs forever
- #1116 — lock leak on tab close
- #1112 — teardown BroadcastChannel race
Suggested fix shape
Attach a handler to dbPromise that records the terminal init failure (name/message/stack); reject waitReady and settled create() callers from that state; stop/catch the retry loop on failure and on closed; in connectTab, reply to tab-here with a failure message so connecting tabs reject immediately.
Happy to send a PR if maintainers agree on the shape.
- Dominant language
- TypeScript
- Stars
- 16.1k
- Forks
- 447
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from electric-sql/pglite
-
Feature request: Nitro 3 support (`unwasm` export condition)Possibly taken @pi0x claimed this 2 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
electric-sql/pglite#1120 · 2 comments ·
Maintainers usually reply within 1 day
-
[BUG]: Parameter count higher than 16bit gets dropped silentlyPossibly taken @Aquiko claimed this 1 day ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
electric-sql/pglite#1118 ·
Maintainers usually reply within 1 day
-
[BUG]: windowed live.query leaks its total-count prepared statement on unsubscribePossibly taken @askalf claimed this 25 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
electric-sql/pglite#1111 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
electric-sql/pglite#1048 ·
Maintainers usually reply within 1 day
-
[BUG]: pglite-sync: after a `must-refetch` a synced table can stay empty; commit errors are swallowedPossibly taken @jeromerg claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 45/100
electric-sql/pglite#1125 ·
Maintainers usually reply within 1 day
All issues in electric-sql/pglite
Similar issues
-
[Bug]: [MCP/CLI] Bare loopback IP addresses (127.0.0.1:port) and hosts with ports fail to navigate due to erroneous scheme inferencePossibly taken @alok-108 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/playwright#43263 ·
Maintainers usually reply within 1 day
-
bug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 75/100
lingdojo/kana-dojo#32018 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
paperclipai/paperclip#15751 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
BuilderIO/agent-native#7275 ·
Maintainers usually reply within 1 day