ninenines / cowboy

Small, fast, modern HTTP server for Erlang/OTP.

Home Page:https://ninenines.eu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upload large files fails

huberts90 opened this issue · comments

I am facing the problem with cowboy, Istio proxy and Go client: client(Go) <-> Istio sidecar <-> Elixir app.
For some reason the stream is being broken if file size exceeds 700 MB. Smaller files are successfully uploaded.
Worth mentioning is the fact, that turning on more verbose debug mode on the client side, pushes the boundary to > 1 GB, anyway this setup finally crashes as well.

Go client:
...
2023/02/22 11:24:48 http2: Transport encoding header "filename" = "test_backup.zip"
2023/02/22 11:24:48 http2: Transport encoding header "session_id" = ""
2023/02/22 11:24:48 http2: Transport encoding header "timestamp" = "1677061488592"
2023/02/22 11:24:48 http2: Transport encoding header "file_type" = "BUG_REPORT"
2023/02/22 11:24:48 http2: Transport encoding header "file_size" = "800000001"
2023/02/22 11:24:48 http2: Transport received SETTINGS len=24, settings: HEADER_TABLE_SIZE=4096, UNKNOWN_SETTING_8=0, MAX_CONCURRENT_STREAMS=2147483647, INITIAL_WINDOW_SIZE=268435456
2023/02/22 11:24:48 http2: Transport encoding header "resume_offset" = "0"
2023/02/22 11:24:48 http2: Transport encoding header "accept-encoding" = "gzip"
2023/02/22 11:24:48 http2: Transport encoding header "user-agent" = "Go-http-client/2.0"
2023/02/22 11:24:48 Unhandled Setting: [UNKNOWN_SETTING_8 = 0]
2023/02/22 11:24:48 http2: Transport received SETTINGS flags=ACK len=0
2023/02/22 11:24:48 http2: Transport received WINDOW_UPDATE len=4 (conn) incr=268369921
2023/02/22 11:24:48 http2: Transport received WINDOW_UPDATE stream=3 len=4 incr=32768
2023/02/22 11:24:48 http2: Transport received WINDOW_UPDATE len=4 (conn) incr=134883430
2023/02/22 11:24:48 http2: Transport received WINDOW_UPDATE stream=3 len=4 incr=134850662
2023/02/22 11:24:49 http2: Transport received WINDOW_UPDATE len=4 (conn) incr=134644788
2023/02/22 11:24:49 http2: Transport received WINDOW_UPDATE stream=3 len=4 incr=134644788
2023/02/22 11:24:49 http2: Transport received WINDOW_UPDATE len=4 (conn) incr=268435456
2023/02/22 11:24:49 http2: Transport received WINDOW_UPDATE stream=3 len=4 incr=268435456
2023/02/22 11:24:49 http2: Transport received WINDOW_UPDATE len=4 (conn) incr=134222658
2023/02/22 11:24:49 http2: Transport received WINDOW_UPDATE stream=3 len=4 incr=134222658
2023/02/22 11:24:52 http2: Transport received HEADERS flags=END_HEADERS stream=3 len=52
2023/02/22 11:24:52 http2: Transport received DATA flags=END_STREAM stream=3 len=87 data="upstream connect error or disconnect/reset before headers. reset reason: protocol error"
    device_crash_report_test.go:114: 
        	Error Trace:	device_crash_report_test.go:114
        	Error:      	Not equal: 
        	            	expected: 413
        	            	actual  : 502
Istio:
2023-02-22T10:20:52.756951Z	debug	envoy connection	[C266] remote close
2023-02-22T10:20:52.756953Z	debug	envoy connection	[C266] closing socket: 0
2023-02-22T10:20:52.757020Z	debug	envoy connection	[C266] SSL shutdown: rc=0
2023-02-22T10:20:52.757051Z	debug	envoy http	[C266][S1797875081780041266] stream reset
Elixir app:
DEF: {1, :no_error,
 %{
   handler_state: %{
     :device_id => "test05132242",
     :file_path => nil,
     :file_type => "BUG_REPORT",
     :timestamp => 1677061488592,
     "accept-encoding" => "gzip",
     "event_id" => "e857326f-adae-43c5-9a3a-6f964416bcba",
     "log_event_type" => "APPLICATION_CRASH",
     "user-agent" => "Go-http-client/2.0",
     "x-b3-parentspanid" => "05dd069a8bb3b550",
     "x-b3-sampled" => "0",
     "x-b3-spanid" => "4139e0290fb69794",
     "x-b3-traceid" => "dc16c23147c0e75705dd069a8bb3b550",
     "x-envoy-attempt-count" => "1",
     "x-envoy-internal" => "true",
     "x-envoy-original-path" => "/api/crash-report/UPLOAD",
     "x-ext-auth-allow" => "yes",
     "x-forwarded-client-cert" => "By=spiffe://cluster.local/ns/arcloud/sa/device-gateway;Hash=0bac23eb5f09fcdf6efa43bf96b2efd142123ccc6fb860698953134ed436ab37;Subject=\"\";URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account",
     "x-forwarded-for" => "10.42.0.166",
     "x-forwarded-proto" => "http",
     "x-request-id" => "916d30bd-23fd-45e8-9953-3d14cbe2ed7d"
   },
   module: CrashReport.UploadHandler,
   opts: %{
     max_file_size: 1000000000,
     module: CrashReport.UploadHandler,
     temp_dir: "/tmp"
   },
   req: %UploadService.Request{
     app_headers: %{
       "accept-encoding" => "gzip",
       "event_id" => "e857326f-adae-43c5-9a3a-6f964416bcba",
       "log_event_type" => "APPLICATION_CRASH",
       "user-agent" => "Go-http-client/2.0",
       "x-b3-parentspanid" => "05dd069a8bb3b550",
       "x-b3-sampled" => "0",
       "x-b3-spanid" => "4139e0290fb69794",
       "x-b3-traceid" => "dc16c23147c0e75705dd069a8bb3b550",
       "x-envoy-attempt-count" => "1",
       "x-envoy-internal" => "true",
       "x-envoy-original-path" => "/api/crash-report/UPLOAD",
       "x-ext-auth-allow" => "yes",
       "x-forwarded-client-cert" => "By=spiffe://cluster.local/ns/arcloud/sa/device-gateway;Hash=0bac23eb5f09fcdf6efa43bf96b2efd142123ccc6fb860698953134ed436ab37;Subject=\"\";URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account",
       "x-forwarded-for" => "10.42.0.166",
       "x-forwarded-proto" => "http",
       "x-request-id" => "916d30bd-23fd-45e8-9953-3d14cbe2ed7d"
     },
     cow_req: %{
       body_length: :undefined,
       cert: :undefined,
       has_body: true,
       headers: %{
         "accept-encoding" => "gzip",
         "event_id" => "e857326f-adae-43c5-9a3a-6f964416bcba",
         "file_hash" => "9a8b7da4f8c4390cfb06fc09d43a3b55e87e090b5477e536f2044226be9e6b40dcc6bf3f4ae9f94626547698788e9292aa59b337cbf0541523140fef3494d302",
         "file_size" => "800000001",
         "file_type" => "BUG_REPORT",
         "filename" => "test_backup.zip",
         "log_event_type" => "APPLICATION_CRASH",
         "resume_offset" => "0",
         "session_id" => "",
         "timestamp" => "1677061488592",
         "token" => "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiY3Jhc2hfcmVwb3J0Il0sImV4cCI6MTcwODU5NzQ4NCwiaXNzIjoibWwtY29ubmVjdGVkLXNlcnZpY2VzIiwicm5kIjo2NDIsInN1YiI6ImIxZGI2MmQyLWUzNzgtZGUxOS0xMjhkLTlhYzE3NjQxMzVlYyJ9.DidcEDZwGrhE7qnxJWdpcUe2vRx3apQYa355F2X84kBHjsUOV1ZGP4SJH6C4rw3etwoqCO5OxgyuZX0omxvMql8v2ZP4uyEXZ-EIsIDNDqeYL_hc8vNDU5-3RgArNSG13U0lJaG7kHn0L8u7N-uvnxYq_7hfHqkR97Jasm5Ba3HGG4cuV2DAluBMY1zojBJou7EfgMgNdFq6sTKqvNEiS8GMUDtejWS4lbbpHF0vmUEcxVfsqThVMDIodQD-K-UH3KzX29O7UwFgNoIOr8PB3afkjv7JV_6UubB64LnuLAyCbFtTViphGNfX-5oPFj1scJgyJOZWwe34JTW1jsxY9A",
         "user-agent" => "Go-http-client/2.0",
         "x-b3-parentspanid" => "05dd069a8bb3b550",
         "x-b3-sampled" => "0",
         "x-b3-spanid" => "4139e0290fb69794",
         "x-b3-traceid" => "dc16c23147c0e75705dd069a8bb3b550",
         "x-envoy-attempt-count" => "1",
         "x-envoy-internal" => "true",
         "x-envoy-original-path" => "/api/crash-report/UPLOAD",
         "x-ext-auth-allow" => "yes",
         "x-forwarded-client-cert" => "By=spiffe://cluster.local/ns/arcloud/sa/device-gateway;Hash=0bac23eb5f09fcdf6efa43bf96b2efd142123ccc6fb860698953134ed436ab37;Subject=\"\";URI=spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account",
         "x-forwarded-for" => "10.42.0.166",
         "x-forwarded-proto" => "http",
         "x-request-id" => "916d30bd-23fd-45e8-9953-3d14cbe2ed7d"
       },
       host: "arcloud.internal",
       method: "POST",
       path: "/UPLOAD",
       peer: {{127, 0, 0, 6}, 57447},
       pid: #PID<0.3485.0>,
       port: 80,
       qs: "",
       ref: {CrashReport.UploadHandler.Ranch, 8089},
       scheme: "http",
       sock: {{10, 42, 0, 148}, 8089},
       streamid: 1,
       version: :"HTTP/2"
     },
     file: {:file_descriptor, :prim_file,
      %{
        handle: #Reference<0.1568887072.3595436059.66350>,
        owner: #PID<0.3485.0>,
        r_ahead_size: 0,
        r_buffer: #Reference<0.1568887072.3595436034.142809>
      }},
     file_hash: "9a8b7da4f8c4390cfb06fc09d43a3b55e87e090b5477e536f2044226be9e6b40dcc6bf3f4ae9f94626547698788e9292aa59b337cbf0541523140fef3494d302",
     file_hash_computed: #Reference<0.1568887072.3597008897.167270>,
     file_path: "/tmp/36189116ea654eda0374220b62820d7b.zip",
     file_size: 800000001,
     file_type: "BUG_REPORT",
     hash_matched?: false,
     id: "36189116ea654eda0374220b62820d7b",
     stream_id: 1,
     succeeded?: false,
     timestamp: 1677061488592,
     token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiY3Jhc2hfcmVwb3J0Il0sImV4cCI6MTcwODU5NzQ4NCwiaXNzIjoibWwtY29ubmVjdGVkLXNlcnZpY2VzIiwicm5kIjo2NDIsInN1YiI6ImIxZGI2MmQyLWUzNzgtZGUxOS0xMjhkLTlhYzE3NjQxMzVlYyJ9.DidcEDZwGrhE7qnxJWdpcUe2vRx3apQYa355F2X84kBHjsUOV1ZGP4SJH6C4rw3etwoqCO5OxgyuZX0omxvMql8v2ZP4uyEXZ-EIsIDNDqeYL_hc8vNDU5-3RgArNSG13U0lJaG7kHn0L8u7N-uvnxYq_7hfHqkR97Jasm5Ba3HGG4cuV2DAluBMY1zojBJou7EfgMgNdFq6sTKqvNEiS8GMUDtejWS4lbbpHF0vmUEcxVfsqThVMDIodQD-K-UH3KzX29O7UwFgNoIOr8PB3afkjv7JV_6UubB64LnuLAyCbFtTViphGNfX-5oPFj1scJgyJOZWwe34JTW1jsxY9A"
   }
 }}

The max_received_frame_rate is 100_000/10 seconds

This is what I have in my appname_app.erl in the cowboy:start_tls area:

max_received_frame_rate => {150000, 10000}

and it works with GB size files.

When the frame limit is involved you should get an enhance_your_calm error not a protocol_error. So not sure why your logs say protocol_error.

An easy to run test case / test repository would be great to help fix this.

Closed in favor of #1523

Default max_frame_size_received will be increased in 2.12. Thanks!