Repository navigation
feat(engine): give each ranged connection its own socket - #4
Conversation
troke12
left a comment
There was a problem hiding this comment.
Good motivation (h2 multiplexes all ranges onto one connection), but as written this breaks segmented HTTPS downloads from HTTP/2 servers (most CDNs):
base.Clone() first runs onceSetNextProtoDefaults on the base; since the base has ForceAttemptHTTP2: true, http2configureTransports sets TLSClientConfig.NextProtos = ["h2", "http/1.1"] (h2_bundle.go). The clone copies that config, so the "HTTP/1-only" transport still offers h2 in ALPN. The server picks h2, TLSNextProto has no "h2" entry, and the transport speaks HTTP/1.1 on an h2 connection → every chunk fails.
Please set t.TLSClientConfig.NextProtos = []string{"http/1.1"} after cloning, and add a TLS test (httptest.NewUnstartedServer with EnableHTTP2 = true + StartTLS) — the current tests use plain HTTP so ALPN never comes up.
Minor: per-download transports never call CloseIdleConnections.
Note for the whole set (#1–#11): thanks a lot for these! They are all branched from 5350f79 independently, so every pair conflicts on CHANGELOG.md and most on download.go. main has also moved (e830f5d adds a stream downloader that touches download.go). Could you rebase onto current main and stack them in this order: #1 → #2 → #10 → #8 → #5/#6/#7/#11? #2, #3 and #10 each add their own pass loop / transferCancel in Start; one shared design would be much easier to merge.
Several ranges on one HTTP/2 connection share a single socket. A segmented download now uses HTTP/1.1, one socket per connection. A single stream still uses the shared client.
Review changes on top of the previous commit: - segmentTransport sets TLSClientConfig.NextProtos to ["http/1.1"]. base.Clone() first sets up HTTP/2 on base, which puts "h2" in its TLS config's ALPN list, and the copy kept it: an HTTP/2 server (most CDNs) picked h2, the transport spoke HTTP/1.1 on it, and every chunk failed with EOF. TestSegmentedDownloadOverHTTP2Server runs over TLS with EnableHTTP2 and fails that way without the fix. - The per-download HTTP/1.1 client closes its idle connections when a run ends; its pool is its own. - TestSegmentedDownloadUsesHTTP1 checks the client goes through the local-network guard (the previous commit, rebased onto main, wraps it with guardLocal like guardedClient). ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
0a4f8e6 to
992b6ea
Compare
|
Rebased onto current |
Summary
Over HTTP/2, all ranged requests of a segmented download are multiplexed onto one TCP connection, so "N connections" gave one socket's throughput. A download with more than one ranged connection now uses a per-download HTTP/1.1 client, so each connection gets its own socket. A single stream, a server without ranges, or the one-connection fallback (#10) keep the shared client and can still use HTTP/2.
Details
segmentTransportclones the shared transport (proxy, pool settings) with HTTP/2 off:ForceAttemptHTTP2=false, an emptyTLSNextProto, and ALPN limited tohttp/1.1. Without the ALPN fix an h2 server picks h2 and every chunk fails (the review's finding).guardLocal) like every other download request. This PR predated the guard; the rebase wraps it. It is rebuilt on the same changes asguardedClient(client or manifest), and its idle connections are closed when a run ends.exchangetakes the client to use;guardManifestLockedis shared withguardedClient.Commits
77c4476(Ryan Bagas): the original change, rebased onto currentmain(guard,exchange, fix(engine): continue on one connection when a range is ignored #10's one-connection mode).992b6ea: review changes. ALPNhttp/1.1, a TLS + HTTP/2 test,CloseIdleConnections, and a guard assertion.Test plan
go test ./...andgo test -race ./internal/engineTestSegmentedDownloadOverHTTP2Server: TLS withEnableHTTP2. The probe uses h2, the segmented requests use HTTP/1.1 on more than one socket, and the file matches. Fails withEOFwithout the ALPN fix.TestSegmentTransportDisablesHTTP2: ALPN is[http/1.1], including from a nil base.TestSegmentedDownloadUsesHTTP1: the HTTP/1.1 client is wrapped by the local-network guard. Fails when it is not.TestOneConnectionKeepsSharedClient,TestNoRangeKeepsSharedClient✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)