sagebind / isahc

The practical HTTP client that is fun to use.
https://docs.rs/isahc
MIT License
712 stars 62 forks source link

[BUG] POST always (sometimes) times out when using `.body(())` #447

Open Vernoxvernax opened 6 months ago

Vernoxvernax commented 6 months ago
isahc = { version = "1.7.2", features = [ "json" ] }
rustc 1.78.0 (9b00956e5 2024-04-29)
curl 8.7.1 (x86_64-pc-linux-gnu) libcurl/8.7.1 OpenSSL/3.3.0 zlib/1.3.1 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 libpsl/0.21.5 libssh2/1.11.0 nghttp2/1.61.0 nghttp3/1.2.0

Sorry, if im mistaken, but it seems that something somewhere changed, so that it's no longer possible to send POST requests with an empty body. They will just time out. I went through the last few commits, but they don't seem to change the versions of the dependencies. Yeah, I know that was all really vague, but here is the kicker: The problem occurs only on some of my pcs. Even though the curl/rust-toolchain versions match. My guess is, that it's a link to some c library or something. As you can tell my knowledge already ended when I clicked New issue, so I'll just leave you these two logs:

Working here:

[2024-05-08T18:46:20Z DEBUG isahc::client] send; method=POST uri=https://rest-e420.immedia-semi.com/api/v1/accounts/123456/networks/123456/sync_modules/123456/local_storage/manifest/request
[2024-05-08T18:46:20Z DEBUG isahc::handler] handler;
[2024-05-08T18:46:20Z DEBUG isahc::handler] handler; id=0
[2024-05-08T18:46:20Z DEBUG isahc::handler] Found bundle for host: 0x77bdfc00f7a0 [can multiplex]
[2024-05-08T18:46:20Z DEBUG isahc::handler] Re-using existing connection #1 with host rest-e420.immedia-semi.com
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [:method: POST]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [:path: /api/v1/accounts/123456/networks/123456/sync_modules/123456/local_storage/manifest/request]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [:scheme: https]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [:authority: rest-e420.immedia-semi.com]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [accept: */*]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [accept-encoding: deflate, gzip]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [token-auth: >:3]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [user-agent: Blink/123456789 CFNetwork/ssss.1 Darwin/haha]
[2024-05-08T18:46:20Z DEBUG isahc::handler] h2h3 [content-type: application/json]
[2024-05-08T18:46:20Z DEBUG isahc::handler] Using Stream ID: 5 (easy handle 0x632510aba090)
[2024-05-08T18:46:20Z DEBUG isahc::handler] Connection #1 to host rest-e420.immedia-semi.com left intact

Not working here:

[2024-05-08T19:26:42Z DEBUG isahc::client] send; method=POST uri=https://rest-e420.immedia-semi.com/api/v1/accounts/123456/networks/123456/sync_modules/123456/local_storage/manifest/request
[2024-05-08T19:26:42Z DEBUG isahc::handler] handler;
[2024-05-08T19:26:42Z DEBUG isahc::handler] handler; id=0
[2024-05-08T19:26:42Z DEBUG isahc::handler] Found bundle for host: 0x7f390800f4c0 [can multiplex]
[2024-05-08T19:26:42Z DEBUG isahc::handler] Re-using existing connection with host rest-e420.immedia-semi.com
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] OPENED stream for https://rest-e420.immedia-semi.com/api/v1/accounts/123456/networks/123456/sync_modules/123456/local_storage/manifest/request
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [:method: POST]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [:scheme: https]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [:authority: rest-e420.immedia-semi.com]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [:path: /api/v1/accounts/123456/networks/123456/sync_modules/123456/local_storage/manifest/request]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [accept: */*]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [accept-encoding: deflate, gzip]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [token-auth: :3]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [user-agent: Blink/123456789 CFNetwork/ssss.1 Darwin/haha]
[2024-05-08T19:26:42Z DEBUG isahc::handler] [HTTP/2] [3] [content-type: application/json]
[2024-05-08T19:27:02Z DEBUG isahc::handler] Operation timed out after 19999 milliseconds with 0 bytes received
[2024-05-08T19:27:02Z DEBUG isahc::handler] Connection #1 to host rest-e420.immedia-semi.com left intact
[2024-05-08T19:27:02Z WARN  isahc::handler] request completed with error: request or operation took longer than the configured timeout time

The Code (simplified):

  let mut builder = Request::post(url)
    .header(header.key, header.value)
    .header("User-Agent", USER_AGENT)
    .header("content-type", "application/json")
  .timeout(Duration::from_secs(20));

  builder.body(()).unwrap().send();

The Fix:

builder.body(String::new()).unwrap().send();
sagebind commented 5 months ago

One clear difference is it seems like different versions of libcurl is being used under the hood on the different machines. Would it be possible to capture the output of isahc::version() on each machine separately for comparison?

Vernoxvernax commented 5 months ago

One clear difference is it seems like different versions of libcurl is being used under the hood on the different machines. Would it be possible to capture the output of isahc::version() on each machine separately for comparison?

Working with:

isahc/1.7.2 (features:default,encoding-rs,http2,json,mime,serde,serde-json,static-curl,text-decoding) libcurl/8.0.1-DEV OpenSSL/3.3.0 zlib/1.3.1 nghttp2/1.45.0

Not working with:

isahc/1.7.2 (features:default,encoding-rs,http2,json,mime,serde,serde-json,static-curl,text-decoding) libcurl/8.6.0-DEV OpenSSL/3.3.0 zlib/1.3.1 nghttp2/1.61.0

Then, I ran cargo update on both machines, now the system that was working before, does not work anymore and also shows:

isahc/1.7.2 (features:default,encoding-rs,http2,json,mime,serde,serde-json,static-curl,text-decoding) libcurl/8.6.0-DEV OpenSSL/3.3.0 zlib/1.3.1 nghttp2/1.61.0
Vernoxvernax commented 4 months ago

@sagebind I was able to observe the same issue in the latest debian bookwork-slim docker image link. Additionally I ran apt install libssl-dev curl. Hope this helps.