fix(pglite-socket): recover query queue after an internal execution error - #1094
Open
Brown-Sage wants to merge 1 commit into
Open
fix(pglite-socket): recover query queue after an internal execution error#1094Brown-Sage wants to merge 1 commit into
Brown-Sage wants to merge 1 commit into
Conversation
…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)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes the queue deadlock described in #1046 (Defect B).
In
QueryQueueManager.processQueue(), a single throw fromexecProtocolRawStream(e.g. a WASM abort or a race withdb.close()) hit thecatchblock which calledquery.reject()and thenreturned — skippingthis.processing = false. Sinceenqueue()only kicks the loopif (!this.processing), one internal failure permanently deadlocked the queue: every subsequent query from any connection was queued and never executed.Changes
processingin afinallyblock so the flag is always restoredcontinuedraining the queue after a failed execution instead of returning, so one bad message doesn't kill the remaining queued queriesRegression tests
New
tests/queue-recovery.test.ts, modeled on the fault-injection repro from #1046:db.execProtocolRawStreamon the firstParsemessage, asserts the failing client gets an error and a fresh connection is still served afterwardBoth tests fail against unfixed
main(queries hang) and pass with this patch.Also adds a changeset for
@electric-sql/pglite-socket.Fixes #1046