Files
seaweedfs/weed/util
c80bf3afac util/http: stop waiting on a response body the server stalls (#12875)
* util/http: stop waiting on a response body the server stalls

CloseResponse reads the rest of a response body so that the connection
can be reused, and StatusError reads the message a server puts in the
body of a failed request. Neither had a time limit. The client's only
read deadline covers the response headers, so when a server sent its
headers and then stopped sending the body, both blocked until the
request's context ended. Most callers pass a context that never ends.

A chunk read whose replica answered 404 or 500 this way never returned,
so it never got to the next replica. That holds for ReadUrlAsStream and
for the replica fallback of S3 copies.

Both now close the body once 5 seconds have passed. That fails the
blocked read, and the connection is dropped instead of reused. A body
that arrives in time is drained as before, and its connection is still
reused. StatusError reports the status with whatever part of the
message arrived.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* util/http: bound a body read that closing the body cannot interrupt

The limit worked by closing the body, which fails a read blocked on it.
That does not hold when the transport decodes gzip for the caller: in Go
1.26 its decoder reads the gzip header under a lock that Close also
takes. A server that announced gzip and stalled before the gzip header
kept both the read and the Close waiting, so the limit never applied.

Such a response is now read on its own goroutine, and the caller stops
waiting when the time is up. The read and the Close stay behind until
the connection dies. Every other response keeps the cheaper way, with
no goroutine.

StatusError now returns the status alone when the message did not
arrive in time. A partly read message is no longer safe to use, because
the read may still be running.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 21:13:49 -08:00
..
2023-11-26 11:47:20 -08:00
2026-11-16 05:31:42 +00:00
2021-08-20 18:38:18 +08:00
2026-02-20 18:42:00 -08:00
2026-02-20 18:42:00 -08:00
2026-02-20 18:42:00 -08:00
2026-02-20 18:42:00 -08:00
2026-02-20 18:42:00 -08:00
2026-02-20 18:42:00 -08:00
2022-09-25 13:34:55 -07:00
2024-10-31 08:40:05 -07:00