-
Notifications
You must be signed in to change notification settings - Fork 18k
bufio: Reader.Read
can return a non-zero count and io.EOF
#52577
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
Comments
I think the bufio docs just need to be updated. The behavior of whether |
Or, why not fix the implementation to match the comment? The comment has been there ~forever, and the behavior it describes — while not strictly required by the |
@bcmills, per my earlier comment, there is a performance implication to removing the early |
Could you provide an example of such a reliance specifically with a |
You can take a look at https://golang.org/cl/21302 and all the referenced CLs and issues. This is one that I can remember, but I know there are other cases. In general, if you read a stream of records of some known length N, the early EOF lets you know that there are no more records incoming and allows you to either return earlier with the results and/or reuse the resources sooner. |
Change https://go.dev/cl/403594 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Playground Link
In the comments of a recent post to Reddit, it was noted that under very specific circumstances,
bufio.Reader.Read
could return a non-zero count andio.EOF
simultaneously. This is despite the docs sayingThis can be read to mean either that it never returns a non-zero count and
io.EOF
, but it can also be read to mean that it will always return a zero count when the underlying reader hits EOF. I'm not entirely sure which is meant, but if it's the first then the code doesn't do what the documentation says, and if it's the latter then it should probably be clarified.What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: