Skip to content

feat: polymorphic helper for request body streaming#485

Open
tank-bohr wants to merge 3 commits intoelixir-mint:mainfrom
tank-bohr:next_body_chunk
Open

feat: polymorphic helper for request body streaming#485
tank-bohr wants to merge 3 commits intoelixir-mint:mainfrom
tank-bohr:next_body_chunk

Conversation

@tank-bohr
Copy link
Copy Markdown
Contributor

See #484 (comment) for details

Remove a redundant HTTP/1 test (HTTP/1 only permits one streaming
request at a time, so the "different ref while streaming" case
collapses into the existing make_ref() test).

Add an HTTP/2 end-to-end test that exercises the documented streaming
loop across multiple iterations with a body larger than the initial
window, processing WINDOW_UPDATE frames between chunks.
Copy link
Copy Markdown
Member

@ericmj ericmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for pushing this through and for sticking with this through multiple revisions.

I left two comments about documentation only.

Comment thread lib/mint/http.ex Outdated
flow-control mechanism: any amount of body data is protocol-valid. The
operating-system socket send buffer may still cause `stream_request_body/3`
to block once it fills up, but that is a transport concern and not
reflected here.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good note to make but it's not H1 specific. In general we cannot guarantee non-blocking unless you set send_timeout on the socket through transport_opts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread lib/mint/http.ex
with {:ok, conn} <- Mint.HTTP.stream_request_body(conn, ref, chunk) do
stream_body(conn, ref, rest)
end
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two issues with this code example.

  • We can return 0 from request_body_window/2 so you can attempt to send an empty binary.
  • There is no backpressure, if there is no window available we will be busy looping, consuming CPU resources.

The latter can be hard to express in a code example because there are many different solutions to it depending on context, so maybe we should just call it out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants