Upstream: reuse connections instead of a fresh one per playlist poll and segment #121
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
cmoriarty/sports-breaker#121
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #118. With gluetun's DNS filter off (#120), the VPN finds and plays the same streams as the home connection. What it still costs is connection setup under bursts, and the app opens a new connection for every request it makes.
What happens
One connection per request:
upstream._client()builds a newhttpx.AsyncClientfor every request (open_upstream,fetch_manifest,fetch_bytes), and closes it afterwards. So every playlist poll and every segment download pays a fresh TCP connection and TLS handshake, and no connection is ever reused.Who makes those requests:
proxy.py);WATCH_LINKS_LIMIT), every 1–3 s.What it costs through the tunnel (measured 2026-11-08 for #118):
When it bites:
The handshake itself is slow: a TLS handshake to these servers takes 200–500 ms on either path, so even without loss each fresh connection adds a quarter to half a second to every fetch of a 2 s segment.
The idea
verify=False), sotls_lenientkeeps working.MANIFEST_TIMEOUT,UPSTREAM_TIMEOUT).open_upstream's callers (proxy.pyin three places,fetch_manifest,fetch_bytes) close only the response. A streaming response still has to be closed or read to the end, so its connection goes back to the pool.set_transport()rebuilds the shared clients, so the lane's scripted upstream still applies (15 tests use it).AsyncHTTPTransport(retries=1)) and test that path.Done when
Closing: merged to develop in PR #123 (merge
f520e51), milestone 40. It deploys once nobody is watching.What changed:
Not seen live yet: fewer "no new segment … ConnectTimeout" failures over a game window behind the VPN.