From d367e0ca8f2ba5726c87c523f4a4d3448de57fac Mon Sep 17 00:00:00 2001 From: shoemoney Date: Tue, 30 Jun 2026 17:27:00 -0500 Subject: [PATCH] =?UTF-8?q?fix(transport):=20SSE=20Events=20reuses=20c.hc?= =?UTF-8?q?=20so=20a=20hung=20connect=20can't=20wedge=20the=20daemon=20?= =?UTF-8?q?=F0=9F=94=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Events() used a bare &http.Client{} (zero timeouts) — a black-holed TCP connect blocked the daemon's reconnect loop forever (backoff only fires on stream error/close, not a stuck connect). The bare client existed to dodge round-1's 30s TOTAL timeout on c.hc; round 2 removed that, so c.hc now bounds dial/TLS with NO total timeout — exactly right for a long-lived SSE stream — and is proxy-aware. One-line swap. --- internal/transport/client.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/transport/client.go b/internal/transport/client.go index 41998e2..a220e60 100644 --- a/internal/transport/client.go +++ b/internal/transport/client.go @@ -61,8 +61,8 @@ func New(base string) *Client { tr.DialContext = (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext tr.TLSHandshakeTimeout = 10 * time.Second tr.ResponseHeaderTimeout = 30 * time.Second - tr.DisableCompression = true // we negotiate gzip explicitly so the rate limiter sees wire bytes - tr.MaxIdleConnsPerHost = 16 // reuse connections for parallel blob transfers + tr.DisableCompression = true // we negotiate gzip explicitly so the rate limiter sees wire bytes + tr.MaxIdleConnsPerHost = 16 // reuse connections for parallel blob transfers return &http.Client{Transport: tr} }(), } @@ -156,7 +156,10 @@ func (c *Client) PutBlob(hash string, data []byte) error { // Events opens an SSE stream of hub change events (optionally filtered to one // share) and calls onEvent for each, until ctx is cancelled or the stream ends. -// Uses a dedicated timeout-less client since the stream is long-lived. +// Reuses c.hc: it bounds dial/TLS (so a black-holed connect can't hang the +// reconnect loop forever) but has no TOTAL timeout, which is what a long-lived +// SSE stream needs — the hub sends headers on connect so ResponseHeaderTimeout +// never trips mid-stream. (A bare client here would also silently drop proxy env.) func (c *Client) Events(ctx context.Context, share string, onEvent func(proto.Event)) error { u := c.base + proto.PathEvents if share != "" { @@ -167,7 +170,7 @@ func (c *Client) Events(ctx context.Context, share string, onEvent func(proto.Ev return err } req.Header.Set(proto.AuthHeader, "Bearer "+c.bearer) - resp, err := (&http.Client{}).Do(req) + resp, err := c.hc.Do(req) if err != nil { return err }