Do i need to read the body before close it?

Found some issues on github about this problem, this on is the most similar:

Seems the problem is related to readers not doing the read with (n, io.EOF).

bradfitz: As background, Go used to auto-drain (around Go 1.0 and Go 1.1 era) but it was problematic for a number of reasons and we changed the behavior to be more predictable but also pushed io.EOFs earlier for many readers and made the final Read-with-EOF on the connection also auto-recycle the TCP connection for people who forget to Close. It seems there’s a Reader not doing early (n, io.EOF) instead of (n, nil)+(0, io.EOF) somewhere.

This CL has a nice information about the readers in the std lib.

net/http and other things work better when io.Reader implementations
return (n, io.EOF) at the end, instead of (n, nil) followed by (0,
io.EOF). Both are legal, but the standard library has been moving
towards n+io.EOF.

In the snippet, this behaviour is not present, i think, but in my app, they may be, need to investigate more.

Thanks for your help guys.

2 Likes