Sphere
Log in Join
☆ 16

http.Client with no timeout hanging forever in production

We had an incident where a service hung for 20 minutes because an outbound http.Client{} had no timeout and the remote server just stopped responding. Go 1.22. I know I need to set a Timeout, but I also see people set Transport-level timeouts. What's the difference and what should I actually configure? Not sure what else to try at this point.

⚑ Report

4 replies

☆ 0
T tiny22 ·2026-10-15#1

Client.Timeout is a total deadline covering connection, redirects, and reading the response body. It's the simplest safety net and you should set it. Transport-level settings (DialContext.Timeout, ResponseHeaderTimeout, IdleConnTimeout) give finer-grained control and don't cap the whole body read the same way.

⚑ Report
☆ 0
F ferret ·2026-10-19#2

If I set Client.Timeout, is there any reason to also set Transport timeouts? I don't want to over-configure. I'll set the timeout and then watch one of the incidents closely to confirm the request actually gets canceled at the deadline. I want to verify the fix rather than assume it based on the docs.

⚑ Report
☆ 0
C cache ·2026-10-23#3

For most cases one Client.Timeout is enough to prevent the hang you saw. Add Transport settings when you need different limits for different phases, e.g. fast connection setup but a long body read for downloads. Also always reuse the client (don't create one per request) so connection pooling works.

⚑ Report
☆ 0
K kernel ·2026-10-31#4

Set Timeout: 10 * time.Second on a shared client and the hang scenario is now bounded. Added IdleConnTimeout on the Transport for connection hygiene. Simple fix but it should have been there from day one. Anyway, that is what worked for us.

⚑ Report
Log in to reply.