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
bufio: Reader swallows 0-length reads #17059
Comments
Without looking into the details of this issue just yet, I'll note that 0-byte reads and writes are inconsistent and ill-defined everywhere in Go. |
Any change to bufio in this regard needs to pay attention to #7611. |
The issue is easy enough to work around if it is documented. I am curious about the original intent behind this behavior. |
Previously every write by an Encoder was written to the underlying connection immediately. This can result in high CPU usage and poor performance on high-latency connections. More importantly, it works around golang/go#17059 .
I think this is a bug. The fix in CL 86590043 for ReadByte (for #7745) incorrectly affected Read as well. Will send a CL. @ianlancetaylor, #7611 is about bufio.Writer, not bufio.Reader, so I think these are mostly independent. |
CL https://golang.org/cl/31320 mentions this issue. |
I have a package that uses bufio.Reader to decode protocol messages. It implements
trace debugging by writing all messages through an
io.Pipe()
. I was surprised to findthat the first 100 0-length writes were ignored by the
bufio.Reader.fill
method, asthe documentation explicitly states
I would like to suggest a documentation change to indicate that zero-length reads are
not counted.
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
A zero-length write to an
io.PipeWriter
, whose correspondingio.PipeReader
was read through abufio.Reader
. The followingsimplified program illustrates the issue: https://play.golang.org/p/lI14R5CMQ-
What did you expect to see?
The program should print one item for every write to the pipe:
What did you see instead?
The bufio.Reader ignored the 0-byte reads.
The text was updated successfully, but these errors were encountered: