Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mint adapter cannot upload more than 65535 bytes on HTTP/2 #394

Open
jayjun opened this issue Jun 16, 2020 · 6 comments
Open

Mint adapter cannot upload more than 65535 bytes on HTTP/2 #394

jayjun opened this issue Jun 16, 2020 · 6 comments
Labels
bug 🔥 mint Issues related to mint adapter workaround

Comments

@jayjun
Copy link

jayjun commented Jun 16, 2020

  • tesla 1.3.3
  • mint 1.1.0

To reproduce,

client = Tesla.client([], Tesla.Adapter.Mint)
Tesla.post(client, "https://httpbin.org/post", String.duplicate("0", 65536))

returns :exceeds_window_size error.

%Mint.HTTPError{
  module: Mint.HTTP2,
  reason: {:exceeds_window_size, :connection, 65535}
}
Full error
{:error,
 %Mint.HTTP2{
   buffer: <<0, 0, 4, 8, 0, 0, 0, 0, 0, 127, 255, 0, 0>>,
   client_settings: %{
     enable_push: true,
     max_concurrent_streams: 100,
     max_frame_size: 16384
   },
   client_settings_queue: {[[]], []},
   decode_table: %Mint.HTTP2.HPACK.Table{
     entries: [],
     length: 0,
     max_table_size: 4096,
     size: 0
   },
   encode_table: %Mint.HTTP2.HPACK.Table{
     entries: [],
     length: 0,
     max_table_size: 4096,
     size: 0
   },
   headers_being_processed: nil,
   hostname: "httpbin.org",
   mode: :active,
   next_stream_id: 5,
   open_client_stream_count: 1,
   open_server_stream_count: 0,
   ping_queue: {[], []},
   port: 443,
   private: %{},
   ref_to_stream_id: %{#Reference<0.4203460067.3989045250.44202> => 3},
   scheme: "https",
   server_settings: %{
     enable_push: true,
     initial_window_size: 65536,
     max_concurrent_streams: 128,
     max_frame_size: 16777215,
     max_header_list_size: :infinity
   },
   socket: {:sslsocket, {:gen_tcp, #Port<0.2811>, :tls_connection, :undefined},
    [#PID<0.1699.0>, #PID<0.1698.0>]},
   state: :open,
   streams: %{
     3 => %{
       id: 3,
       received_first_headers?: false,
       ref: #Reference<0.4203460067.3989045250.44202>,
       state: :open,
       window_size: 65536
     }
   },
   transport: Mint.Core.Transport.SSL,
   window_size: 65535
 },
 %Mint.HTTPError{
   module: Mint.HTTP2,
   reason: {:exceeds_window_size, :connection, 65535}
 }}

That is because window_size: 65535 is set initially, according to standard, but is not updated when the server sends WINDOW_UPDATE frames.

Each time Tesla sends data using Mint.HTTP.stream_request_body, the window size is decremented by data’s size. When the window size gets low, the server sends WINDOW_UPDATE frames to increment the connection’s window size. Calling Mint.HTTP.stream to read responses will automatically do this.

https://github.com/teamon/tesla/blob/754d4a6ffe41ff508fc7fa460508a40e965b2960/lib/tesla/adapter/mint.ex#L178-L187

However, the adapter repeatedly calls Mint.HTTP.stream_request_body without calling Mint.HTTP.stream so the window size hits zero and Mint errors.

@teamon
Copy link
Member

teamon commented Jul 22, 2020

Hi @jayjun, thanks for reporting the issue.
Would you be able to provide the fix as a PR?

@jayjun
Copy link
Author

jayjun commented Jul 22, 2020

Unfortunately not at the moment because I don’t have the bandwidth to learn Tesla internals, Mint and HTTP/2 enough to do a good job.

@slapers
Copy link

slapers commented Apr 8, 2022

If someone hits this error until this is solved, as a temporary solution
you can force the connection to be http1 by adding some options for the adapter:

Tesla.post(client, url, content, [opts: [adapter: [protocols: [:http1]]]])

@sheharyarn
Copy link

Bumping this since this is a serious issue!

Thank you for all the work on Tesla!

@yordis
Copy link
Member

yordis commented Mar 14, 2023

@sheharyarn do you have some bandwidth to tackle the issue?

@sheharyarn
Copy link

@yordis I can definitely try, but would need someone to push me in the right direction. While I have a good amount of experience with Tesla in general, I don't have enough experience with Mint's internals.

OmegaNalphA added a commit to withbroadcast/openai that referenced this issue Oct 13, 2023
There's a well documented error with Tesla where the http2 cannot send more than 65535 bytes. The issue is documented here: elixir-tesla/tesla#394

This is a workaround until Tesla gets their workaround implemented.
joshk added a commit to joshk/nerves_hub_cli that referenced this issue Apr 17, 2024
http2 file uploads were causing consistent errors due to the window size not being updated by the mint adapter

elixir-tesla/tesla#394
jjcarstens pushed a commit to nerves-hub/nerves_hub_cli that referenced this issue Apr 17, 2024
http2 file uploads were causing consistent errors due to the window size not being updated by the mint adapter

elixir-tesla/tesla#394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 mint Issues related to mint adapter workaround
Projects
Status: Todo
Development

No branches or pull requests

5 participants