fix(linux): persistent HTTP/1.1 connection pool to prevent parallel-request timeout#949
fix(linux): persistent HTTP/1.1 connection pool to prevent parallel-request timeout#949bl4ckswordsman wants to merge 4 commits intoedde746:mainfrom
Conversation
|
Hey @edde746 could I please get some input, is this not up to standards? It's only 35 lines, linux-specific, and fixes some timeouts related to caddy/http2 use cases which I constantly get without this patch. |
|
Been busy with adding Jellyfin support, I believe there was an issue with doing this which led to me switching to native HTTP clients where available. Also:
|
|
My bad for disturbing and interrupting your flow. And thanks for the input. I removed the duplicate probe fire and unused Regarding the Since these callers have seemingly no reason to share the Plex connection pool, perhaps they should use a plain disposable client instead(?): // fribb_mapping_store.dart and all tracker service constructors
- _http = httpClient ?? platform.createPlatformClient();
+ _http = httpClient ?? http.Client();
What do you think about this? (whenever you have a few minutes to spare ofc) I wanted to keep the patch clean and the scope of this PR as narrow as possible. But if it gets too broad or too complicated, and since you mentioned you had issues with this approach before, I might just have to give up on it and keep building a patched version on my own. Thanks anyways! |
Problem: Linux lacks a native HTTP/2 client in the Dart ecosystem (dart-lang/http#1385). Every PlexHttpClient created a fresh IOClient, meaning each of the 10+ parallel home-screen requests (on-deck, hubs, metadata) opened a separate TCP+TLS handshake. Dart's default maxConnectionsPerHost = 6 caused trailing requests to queue past the 10s connect timeout, triggering spurious failover to unreachable LAN/plex.direct candidates.
Additionally, PlexHttpClient.close() called IOClient.close() which called HttpClient.close() internally - destroying all keep-alive connections and forcing cold handshakes on every reconnect.
Fix:
Added a file-level HttpClient singleton for Linux with maxConnectionsPerHost = 12 and idleTimeout = 90s. createPlatformClient() wraps it so all PlexHttpClient instances share one pool.
Added closePlexClient() - no-op on Linux, normal close() elsewhere. PlexHttpClient.close() now delegates to this instead of calling _client.close() directly.
Added createProbeClient() - returns a fresh, disposable IOClient for connection testing that cannot accidentally close the singleton pool.Stub versions of all three functions added to platform_http_client_stub.dart for web compile compatibility.
Android/iOS/Windows behaviour is unchanged.
Also fixes #929 in my testing.