add async streaming tests and fix chunked bug #181
Merged
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.
All of our streaming response tests wrote out their bodies synchronously
in the request handler, so here we add some tests that observe the write
loop yielding in between writes. In doing this, we expose a latent bug
regarding non-chunked, 0-byte streaming responses, which could get the
writer into a stuck state.
What was happening was we relied on
transfer_to_writer_with_encoding
to pass the encoding along and flip the
write_final_if_chunked
tofalse
, but since we have no body, that bool never gets flipped and thebody thinks it is chunked. This is an issue because
t.write_final_if_chunked
determines whether or not the body haspending output, even though it might be a noop.
So roughly:
were written and the body is empty. However, because the body thinks
it is chunked, it does report pending output, and so the writer is
never closed.
nothing to wake it up.
The change here is to see if we need to unset
write_final_if_chunked
regardless of the next faraday operation. This way, when our only
operation is a single
Close
, we'll be in the correct state.I also wanted to make another change where we don't call
done_waiting
in
respond_with_streaming
withflush_headers_immediately=false
, thedefault. The way it works now, we wake up the runtime's writer, but only
after putting our connection writer into a yield state, which means the
runtime writer immediately yields. However, when this happens, the
continuation effectively moves from the reqd to the body. We could just
pass the continuation along instead of calling
done_waiting
, but sincewe're reworking the flow of things in another branch, simply documenting
this seemed fine.