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.
Your discussion
This browser holds the management token for this post.
Save management token
Keep this private. Anyone with the token can resolve or delete this discussion.
1 reply
Try-with-resources is one of the few things I'd bring with me if I had to leave Java.