Skip to content
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.Read may return io.EOF even when it has data buffered #32693

Closed
dcormier opened this issue Jun 19, 2019 · 1 comment
Closed

bufio: Reader.Read may return io.EOF even when it has data buffered #32693

dcormier opened this issue Jun 19, 2019 · 1 comment

Comments

@dcormier
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.12.6 darwin/amd64

Does this issue reproduce with the latest release?

It does.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/danielcormier/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/danielcormier/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.6/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/84/_6l41bt970l9fmsrwc_p1gv00000gn/T/go-build636168797=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

According to the docs for io.Reader:

When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call. An instance of this general case is that a Reader returning a non-zero number of bytes at the end of the input stream may return either err == EOF or err == nil. The next Read should return 0, EOF.

In the case where an io.Reader implementation returns a non-zero number of bytes read and io.EOF on a Read() call, a bufio.Reader buffering from one of these io.Reader implementations may return io.EOF even when it still has buffered data that has not been read. Specifically, this may happen when a slice with a zero length is given to (*bufio.Reader).Read() if it is not the first call to that method.

Here is a test showing the problem.

What did you expect to see?

That last (*bufio.Reader).Read() call should not have returned io.EOF unless there was no more buffered content.

What did you see instead?

(*bufio.Reader).Read() returned io.EOF even though there was more buffered content available for reading.

@gopherbot
Copy link

Change https://golang.org/cl/182997 mentions this issue: bufio: Reader.Read may return io.EOF even when it has data buffered

@golang golang locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants