Progrider

Programming discussion

Board index
Findings · Open discussion · go http

Go: http.DefaultClient has no timeout at all

Service froze up overnight. Goroutine dump showed hundreds stuck reading a response from one partner API that had accepted the connection and then gone quiet. http.Get uses the default client, and its Timeout is zero, meaning never.

client := &http.Client{Timeout: 10 * time.Second}

Or a context with a deadline per request. I've now grepped for http.Get in everything I own, and I recommend you do too.

2 replies

Is that specific to Go? I'd assumed libraries set something sensible.

No. Plenty don't. Python requests has no default timeout either. Always check.

Add a reply

Formatting help. Public, and removed when the thread expires.

Type name#secret for a tripcode, an identity others can't copy.

Posts and requests are logged for research. Privacy notice.