fix(world-postgres): remove stream reader listeners on EOF, query failure, and close - #3158
Open
Mohith26 wants to merge 2 commits into
Open
fix(world-postgres): remove stream reader listeners on EOF, query failure, and close#3158Mohith26 wants to merge 2 commits into
Mohith26 wants to merge 2 commits into
Conversation
…lure, and close streams.get() registered an EventEmitter listener per reader but only removed it when the consumer explicitly cancelled the ReadableStream. Three other terminal paths leaked the listener: a persisted EOF chunk closing the controller, the initial chunk query rejecting, and createStreamer().close() (used by world.close()). Give each reader a single idempotent cleanup that is invoked from all four terminal paths, and track active reader cleanups in the streamer so close() drains them. Repeated reads of a completed or failing stream no longer accumulate listeners or trigger MaxListenersExceededWarning. Fixes vercel#3120
…minal paths Add unit tests around createStreamer() with a mocked pg client and a minimal fake drizzle chain, capturing the internal EventEmitter via a prototype spy to assert listener counts: - 12 repeated reads to EOF leave zero listeners and emit no MaxListenersExceededWarning - a rejecting initial chunk query removes the listener - streamer close() detaches 10 active (uncancelled) readers - explicit consumer cancellation still cleans up (control)
|
Contributor
|
@Mohith26 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #3120
What
world-postgresstream readers registered anevents.on('strm:<name>', onData)listener whose cleanup only ran on explicitReadableStream.cancel(). EOF close, initial-query rejection, andcreateStreamer().close()all left listeners attached, so repeated reads of a completed or failing stream accumulated listeners untilMaxListenersExceededWarning, and closed readers were retained.Each reader now owns a single idempotent cleanup invoked from all four terminal paths, and the streamer tracks active reader cleanups so
close()detaches everything that remains. No public API changes.Tests
Mock-based unit tests (fake pg client, no live Postgres) assert listener counts return to zero on all four paths, including 12 repeated EOF reads with no warnings. With the fix stashed, 3 of the 4 new tests fail with exactly the leaked counts; with it, the package suite is 30/30. Typecheck and biome clean.
Credit to @Jiarui-Ni for the detailed report in #3120.