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: Writer.ReadFrom ignores the stored error #35194

Closed
pam4 opened this issue Oct 27, 2019 · 6 comments
Closed

bufio: Writer.ReadFrom ignores the stored error #35194

pam4 opened this issue Oct 27, 2019 · 6 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@pam4
Copy link

pam4 commented Oct 27, 2019

If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes, and Flush, will return the error.

type writer struct{}

func (w writer) Write(p []byte) (n int, err error) {
	return 0, errors.New("bad move")
}

func main() {
	var wr = bufio.NewWriter(writer{})
	wr.WriteString("test1") // 5 <nil>
	wr.Flush()              // bad move
	wr.ReadFrom(strings.NewReader("test2")) // 5 <nil>
	wr.Buffered() // 10
}

https://play.golang.org/p/--WBbDHbIS9

no more data will be accepted

Then I would expect ReadFrom to fail and the Buffered() count not to grow.

all subsequent writes [...] will return the error.

Isn't ReadFrom a write?

This seems unlikely to have bad consequences, but I don't think it's a valid reason for the documentation to be incorrect about corner cases.

@FiloSottile FiloSottile added help wanted NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Oct 28, 2019
@FiloSottile FiloSottile added this to the Go1.14 milestone Oct 28, 2019
@FiloSottile
Copy link
Contributor

This definitely looks like a bug. It also calls the underlying ReadFrom without persisting the error.

@gopherbot
Copy link

Change https://golang.org/cl/203999 mentions this issue: bufio: fix writer ReadFrom do not set underlying error

@gopherbot
Copy link

Change https://golang.org/cl/204000 mentions this issue: bufio: returns the underlying error in ReadFrom if not nil

gopherbot pushed a commit that referenced this issue Oct 31, 2019
Updates #35194

Change-Id: Ib854bc6250ddeb606d6ff6240179e23b98e4ac62
Reviewed-on: https://go-review.googlesource.com/c/go/+/203999
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@tandr
Copy link

tandr commented Nov 1, 2019

Will it be backported to 1.13 and 1.12 ?

@cuonglm
Copy link
Member

cuonglm commented Nov 1, 2019

cc @bradfitz @bcmills

@bcmills
Copy link
Contributor

bcmills commented Nov 1, 2019

Will it be backported to 1.13 and 1.12 ?

If it's not a regression from 1.11 and not a security issue, then a backport seems doubtful. (Do we know whether it's a regression from 1.11?)

@golang golang locked and limited conversation to collaborators Oct 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

6 participants