New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: Reader.Read called after receiving EOF #50155
Comments
It's unclear to me if a Read method can be called after returning EOF. I cannot find it documented one way or another. cc @neild |
Looks like it's
|
The I'm going to close this because I don't think there is anything to change in the Go library. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have very simple Reader that has a channel and
Read
function:The Read function returns
0, io.EOF
to indicate that the reader has reached to the end of the file and should not be called again.I use MyReader as HTTP request body, like in the complete example below, and I send 1000000 such a requests to a simple web server.
I execute the code above on command line
and I get an
panic: close of closed channel
quite consistently. The error is not thrown every time but about one out of three runs.I noticed that if the sleep between the request is fixed to some value, the error is thrown much less frequently. But with random sleep interval between 10-110 microseconds, the error is easier to reproduce.
What did you expect to see?
I expect that the
Read
function would not be called after the MyReader has returned(0, io.EOF)
. I noticed that some of theReader
implementations (like this one) usesync.Mutex
and boolean flags to return early fromRead
call when EOF had been seen first time.However, it seems like a bug that most of the time the first
io.EOF
is enough to liberate the Reader from reading, but sometimes there are still Read calls after(0, io.EOF)
has been returned.What did you see instead?
After running the program few times, I see following stack trace:
The text was updated successfully, but these errors were encountered: