Skip to content

fix(pglite-socket): recover query queue after an internal execution error - #1094

Open
Brown-Sage wants to merge 1 commit into
electric-sql:mainfrom
Brown-Sage:fix/socket-queue-deadlock-on-error
Open

fix(pglite-socket): recover query queue after an internal execution error#1094
Brown-Sage wants to merge 1 commit into
electric-sql:mainfrom
Brown-Sage:fix/socket-queue-deadlock-on-error

Conversation

@Brown-Sage

Copy link
Copy Markdown

Description

Fixes the queue deadlock described in #1046 (Defect B).

In QueryQueueManager.processQueue(), a single throw from execProtocolRawStream (e.g. a WASM abort or a race with db.close()) hit the catch block which called query.reject() and then returned — skipping this.processing = false. Since enqueue() only kicks the loop if (!this.processing), one internal failure permanently deadlocked the queue: every subsequent query from any connection was queued and never executed.

Changes

Regression tests

New tests/queue-recovery.test.ts, modeled on the fault-injection repro from #1046:

  1. Injects a single rejection into db.execProtocolRawStream on the first Parse message, asserts the failing client gets an error and a fresh connection is still served afterward
  2. Same injection with two concurrent connections; client B must complete regardless of A hitting the injected failure

Both tests fail against unfixed main (queries hang) and pass with this patch.

Also adds a changeset for @electric-sql/pglite-socket.

Fixes #1046

…rror

A single throw from execProtocolRawStream (e.g. a WASM abort or a race
with db.close()) left processQueue() with processing stuck at true, so
enqueue() never restarted the loop and every subsequent query from any
connection hung forever.

Reset the flag in a finally block and continue draining the queue after
a failed execution. Transaction affinity semantics are unchanged.

Fixes electric-sql#1046 (Defect B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: pglite-socket: concurrent extended-protocol batches interleave across connections; one internal throw permanently deadlocks the query queue

1 participant