Skip to content

fix(mint): avoid failing large HTTP/2 uploads#842

Draft
yordis wants to merge 8 commits intomasterfrom
yordis/fix-http2-upload-flow-control
Draft

fix(mint): avoid failing large HTTP/2 uploads#842
yordis wants to merge 8 commits intomasterfrom
yordis/fix-http2-upload-flow-control

Conversation

@yordis
Copy link
Copy Markdown
Member

@yordis yordis commented Apr 18, 2026

  • Large HTTP/2 uploads currently fail once the request body exceeds Mint's flow-control window.
  • Streamed HTTP/2 uploads can crash instead of recovering when window updates arrive mid-request.
  • Tesla should handle larger HTTP/2 request bodies without forcing callers to fall back to HTTP/1.

Copilot AI review requested due to automatic review settings April 18, 2026 18:50
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 18, 2026

PR Summary

Medium Risk
Changes request-body streaming logic for HTTP/2 (chunking, window-update handling, and header tweaks), which can affect upload behavior and error handling across protocols. Coverage is improved with new integration tests for large bodies and early server responses.

Overview
Fixes large HTTP/2 uploads in Tesla.Adapter.Mint by switching non-empty HTTP/2 request bodies into a controlled streaming path, ensuring content-length is set, and chunking request data with flow-control/window-update aware retries when Mint reports :exceeds_window_size.

Also propagates any response data received during upload into format_response/4, so callers can return :plain, :chunks, or :stream bodies even when the server responds early. Adds new Cowboy-based test coverage for large HTTP/2 bodies and early-response scenarios, plus a small test support handler.

Reviewed by Cursor Bugbot for commit e71334b. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Mint adapter to support large HTTP/2 request bodies by streaming uploads and respecting HTTP/2 flow-control windows, preventing failures/crashes on large or streamed uploads.

Changes:

  • Add HTTP/2-aware request-body streaming that waits for flow-control window updates and splits chunks accordingly.
  • Thread an accumulated “early response” accumulator through the request/response pipeline so window updates (and any early response frames) can be processed mid-upload.
  • Add regression tests for large HTTP/2 uploads (binary body and streamed body).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/tesla/adapter/mint.ex Streams HTTP/2 request bodies (including previously non-streaming iodata) and waits for flow-control window before writing chunks.
test/tesla/adapter/mint_test.exs Adds tests covering large HTTP/2 uploads and helpers to generate/verify posted payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/tesla/adapter/mint.ex Outdated
Comment thread lib/tesla/adapter/mint.ex Outdated
Comment thread test/tesla/adapter/mint_test.exs
Comment thread lib/tesla/adapter/mint.ex
@yordis yordis requested a review from Copilot April 18, 2026 21:05
@yordis yordis marked this pull request as draft April 18, 2026 21:06
Comment thread lib/tesla/adapter/mint.ex
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

lib/tesla/adapter/mint.ex:322

  • receive_headers_and_status/4 always calls receive_packet/4 before checking whether acc already contains :status and :headers. Since acc can now be pre-populated from request-body streaming (e.g., while waiting for HTTP/2 window updates), this can cause an unnecessary extra receive and potentially block/timeout even though the headers/status are already available. Add a fast-path that returns immediately when acc already has both keys.
    defp receive_headers_and_status(conn, ref, opts, acc) do
      with {:ok, conn, acc} <- receive_packet(conn, ref, opts, acc) do
        case acc do
          %{status: _status, headers: _headers} -> {:ok, conn, acc}
          # if we don't have status or headers we try to get them in next packet
          _ -> receive_headers_and_status(conn, ref, opts, acc)
        end

lib/tesla/adapter/mint.ex:300

  • receive_responses/4 now accepts an initial acc, but it still unconditionally calls receive_packet/4 first. If acc already contains :done (or all response data) from earlier receives during HTTP/2 upload flow-control handling, this will wait for an extra packet and may block/timeout. Consider checking acc[:done] (and running check_data_size/3) before attempting another receive_packet/4 call.
    defp receive_responses(conn, ref, opts, acc) do
      with {:ok, conn, acc} <- receive_packet(conn, ref, opts, acc),
           :ok <- check_data_size(acc, conn, opts) do
        if acc[:done] do
          if opts[:close_conn], do: {:ok, _conn} = close(conn)
          {:ok, acc}
        else
          receive_responses(conn, ref, opts, acc)
        end

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/tesla/adapter/mint.ex Outdated
yordis added 5 commits April 22, 2026 16:49
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the yordis/fix-http2-upload-flow-control branch from 55a397e to 0b0486c Compare April 22, 2026 21:42
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ff091ff. Configure here.

Comment thread lib/tesla/adapter/mint.ex
yordis added 2 commits April 22, 2026 19:43
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
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