Repository navigation
Return chunks an enumerable body yields from a nested fiber. - #42
Open
cole-robertson wants to merge 1 commit into
Open
cole-robertson wants to merge 1 commit into
cole-robertson wants to merge 1 commit into
Conversation
`Body::Enumerable#read` used `to_enum(:each).next`. `Enumerator#next` is built on `Fiber.yield`, so a chunk the body yields from inside a fiber it created goes to whoever resumed that fiber, not to the reader, and is dropped. Rails' `render stream: true` renders its layout in such a fiber, so on Falcon the response was `200` with an empty or partial body. Enumerate the body in a fiber of its own and transfer each chunk back to the reader using `Fiber#transfer`, following the precedent in socketry#16. Errors raised by the body still reach the reader, and a `StopIteration` from the body still ends the read.
3 tasks done
This branch has not been deployed
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.
Body::Enumerable#readreads the body withto_enum(:each).next.Enumerator#nextis built onFiber.yield, so when the body yields a chunk from inside a fiber it created, the chunk goes to whoever resumed that fiber instead of the reader, and is dropped.Rails'
render stream: truedoes this:ActionView::StreamingTemplateRendererrenders the layout in aFiberso the template can be rendered when the layout reachesyield. On Falcon, a streamed template comes back as200with an empty or partial body. Puma and other servers call#eachdirectly, so they're unaffected.This enumerates the body in a fiber of its own and transfers each chunk back to the reader with
Fiber#transfer, following the precedent in #16. Otherwisereadbehaves as before: an exception raised by the body is raised in the reader and the next read starts the body again, aStopIterationfrom the body ends the read, reading after the end returnsnil, andclosecloses the wrapped body. A body that previously lost its nested-fiber chunks may now also raise errors that came after them.Reproduction (no Rails needed)
On main:
["template"]. With this change:["<html>", "template", "</html>"].Through Falcon 0.57.0, a Rails 8.1 app's
render stream: truereturned 0 of 8 complete responses before this change and 8 of 8 after. The other streaming paths (anEnumeratorbody, a callable body,ActionController::Live,send_streamand Active Storage's proxy) returned the same results before and after.Types of Changes
Contribution