[Flight] Fix stranded row content under Node stream backpressure#36516
Open
unstubbable wants to merge 1 commit into
Open
[Flight] Fix stranded row content under Node stream backpressure#36516unstubbable wants to merge 1 commit into
unstubbable wants to merge 1 commit into
Conversation
The Flight Server emits Text and TypedArray rows as two chunks: a header that gives the row's id, type, and content length, followed by the content itself. These two chunks were pushed into `completedRegularChunks` (and `completedDebugChunks` in DEV) as separate items, so when the destination signaled backpressure between them, the flush would write the header and then break out before reaching the content. The content chunk was left stranded at the head of the queue. Async work running while the destination was paused appended new rows to `completedImportChunks` / `completedHintChunks`, and the next drain flushed those queues first — splicing the newly-arrived bytes into the position the Flight Client expects to read as the original row's content. From there the Flight Client read rows from the wrong byte offsets and the model failed to deserialize. This only surfaced on the Node stream path. `createFakeWritableFromReadableStreamController`, used by `renderToReadableStream`, always returns `true` from `write()`, so the flush loop never saw backpressure. The fix pushes each pair as a single tuple `[headerChunk, contentChunk]` into `completedRegularChunks` and `completedDebugChunks`. The flush loops now write every part of a tuple before re-checking backpressure, so backpressure can still break between rows but never within one.
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.
The Flight Server emits Text and TypedArray rows as two chunks: a header that gives the row's id, type, and content length, followed by the content itself. These two chunks were pushed into
completedRegularChunks(andcompletedDebugChunksin DEV) as separate items, so when the destination signaled backpressure between them, the flush would write the header and then break out before reaching the content. The content chunk was left stranded at the head of the queue. Async work running while the destination was paused appended new rows tocompletedImportChunks/completedHintChunks, and the next drain flushed those queues first — splicing the newly-arrived bytes into the position the Flight Client expects to read as the original row's content. From there the Flight Client read rows from the wrong byte offsets and the model failed to deserialize.This only surfaced on the Node stream path.
createFakeWritableFromReadableStreamController, used byrenderToReadableStream, always returnstruefromwrite(), so the flush loop never saw backpressure.The fix pushes each pair as a single tuple
[headerChunk, contentChunk]intocompletedRegularChunksandcompletedDebugChunks. The flush loops now write every part of a tuple before re-checking backpressure, so backpressure can still break between rows but never within one.