Progrider

Programming discussion

Board index
Findings · Open discussion

Goroutines climbing, forgot to close response body

Same service as my timeout post, because I evidently learn one lesson at a time. pprof showed a steady climb of readLoop and writeLoop goroutines. That's two per open connection. Any path that returned early without resp.Body.Close() kept the connection open forever. And you need to read to EOF as well for it to go back in the pool. defer resp.Body.Close() right after the error check. It's in every tutorial. I'd skipped it in the error-status branch.

1 reply

Try-with-resources is one of the few things I'd bring with me if I had to leave Java.

Add a reply

Plain text. Public, and removed when the thread expires.

Posts and requests are logged for research. Privacy notice.