fix(transport): SSE Events reuses c.hc so a hung connect can't wedge the daemon 🔌

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.
This commit is contained in:
shoemoney 2026-06-30 17:27:00 -05:00
parent 55e1e77fc6
commit d367e0ca8f

View file

@ -61,8 +61,8 @@ func New(base string) *Client {
tr.DialContext = (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext tr.DialContext = (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext
tr.TLSHandshakeTimeout = 10 * time.Second tr.TLSHandshakeTimeout = 10 * time.Second
tr.ResponseHeaderTimeout = 30 * time.Second tr.ResponseHeaderTimeout = 30 * time.Second
tr.DisableCompression = true // we negotiate gzip explicitly so the rate limiter sees wire bytes tr.DisableCompression = true // we negotiate gzip explicitly so the rate limiter sees wire bytes
tr.MaxIdleConnsPerHost = 16 // reuse connections for parallel blob transfers tr.MaxIdleConnsPerHost = 16 // reuse connections for parallel blob transfers
return &http.Client{Transport: tr} 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 // 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. // 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 { func (c *Client) Events(ctx context.Context, share string, onEvent func(proto.Event)) error {
u := c.base + proto.PathEvents u := c.base + proto.PathEvents
if share != "" { if share != "" {
@ -167,7 +170,7 @@ func (c *Client) Events(ctx context.Context, share string, onEvent func(proto.Ev
return err return err
} }
req.Header.Set(proto.AuthHeader, "Bearer "+c.bearer) req.Header.Set(proto.AuthHeader, "Bearer "+c.bearer)
resp, err := (&http.Client{}).Do(req) resp, err := c.hc.Do(req)
if err != nil { if err != nil {
return err return err
} }