-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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 cannot buf content greater than 32KB #33264
Comments
/cc @ianlancetaylor I was able to reproduce the described behavior by running the code in https://play.golang.org/p/i4IqIQPMqFd locally. |
We could check in |
This is likely a dup of #16474. |
@randall77 I meet this bug again and it's difficult and confusing to locate this bug, is it ok to fix it use the workaround? I'd like to submit a change about it. |
Which workaround do you mean? There are a few in this thread and in #16474. |
you can use |
Closing as duplicate of #16474 |
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?
https://play.golang.org/p/i4IqIQPMqFd
Run the server, then just curl it.
What did you expect to see?
The buffer should work, then the output should be:
What did you see instead?
Investigation
To reduce the copy buffer, io.Copy will follow the behavior of WriterTo and ReaderFrom firstly.
bufio.Reader
implements WriterTo, which will call the w's ReadFrom if possible.And the implementation of http.ResponseWriter is
http.(*response)
, it implements ReaderFrom to optimize for sendfile. But it has a bad fallback behavior on non-file reader, it callio.CopyBuffer
with a small buffer(32KB), which break the buffer behavior of bufio.Reader.All of above caused the unexpected behavior that bufio.Reader really can not buf anything more than 32KB.
A workaround is just wrap a nothing reader wrapped on *bufio.Reader, but it's not elegant.
The text was updated successfully, but these errors were encountered: