Repository navigation
fix(pg-cursor): settle every read when reads overlap - #3813
Open
Kesavamoorthig06 wants to merge 1 commit into
Open
Kesavamoorthig06 wants to merge 1 commit into
Kesavamoorthig06 wants to merge 1 commit into
Conversation
Two overlapping read() calls corrupted the cursor state machine: the row description handler shifted the queued read while the first read was still busy, overwriting the active callback so the first read never settled, and the batch delivery path never drained the queue. Guard the queue shifts in handleRowDescription/_ifNoData against the busy state and drain the queue from _sendRows once the active read settles.
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.
Problem
When two
read()calls on the sameCursoroverlap, the first promise never settles.Repro (against any running postgres):
Cause
The second
read()submits while the connection is stillbusywith the first read's portal.handleRowDescription(and_ifNoData) unconditionally shift the submission queue and overwritethis._cbwhilethis._state === 'busy', clobbering the first read's callback. On top of that,_sendRowsreturns after delivering rows without shifting the queue, so a read that was queued behind an in-flight read is never started when the connection goes idle.Fix
handleRowDescription/_ifNoData, only shift the queue and install_cbwhen the connection is not busy; a busy connection means the next read's portal was already sent bynextand the shift happened there._sendRows, after delivering rows, if the connection is idle and more reads are queued, start the next one via_shiftQueue.Adds a regression test (
concurrent reads settle in order) that fails without the fix (mocha 2s timeout) and passes with it.