-
Notifications
You must be signed in to change notification settings - Fork 18.1k
net/http: body argument to NewRequest is closed multiple times #19186
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
See: golang/go#19186 When the body isn't fully read and Close is called multiple times we put the same buffer in the pool multiple times causing it to be reused by multiple goroutines at the same time.
Yeah, I feel like I've seen this too, or that there was an existing comment on a CL or a bug or TODO about this. Thanks for filing. |
I'm taking a look at this. |
I have a test that replicates the double close. |
CL https://golang.org/cl/37298 mentions this issue. |
I have a fix. Check it out and let me know what you think. |
@nerdatmath please check the CL, I think one more round to fix some docs then we'll be gucci. |
I'm traveling at the moment unfortunately. Can it wait about 9 days?
…On Sun, Jun 25, 2017, 06:40 Emmanuel T Odeke ***@***.***> wrote:
@nerdatmath <https://github.com/nerdatmath> please check the CL, I think
one more round to fix some docs then we'll be gucci.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#19186 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AClAHkArM9kHTmR-AuKQTmf87eIi3NGEks5sHeS1gaJpZM4MFYOM>
.
|
@nerdatmath, no, 9 days is too late. But somebody can take it over before then. Ideally in the next 24 hours. @odeke-em? |
Working on it right now... |
Why not permit it? What is the harm in allowing close to be called multiple times, the error is ignored anyway. |
Because the https://golang.org/pkg/io/#Closer
So the conservative thing to do as a user of an The second call might panic or deadlock. |
Fair enough.
…On Mon, 26 Jun 2017, 11:12 Brad Fitzpatrick ***@***.***> wrote:
Why not permit it? What is the harm in allowing close to be called
multiple times, the error is ignored anyway.
Because the io.Closer interface does not specify how implementations must
behave on double Close. In fact, it says:
https://golang.org/pkg/io/#Closer
The behavior of Close after the first call is undefined.
So the conservative thing to do as a user of an io.Closer is not ever
call it twice.
The second call might panic or deadlock.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#19186 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA6-cEMK_RFl5DMvJ4BfAbO9jhLMNks5sHwWXgaJpZM4MFYOM>
.
|
When passing an
ReadCloser
as body tohttp.NewRequest
, it is possible theClose()
of theReadCloser
is called multiple times for the same request. I'm wondering if this is allowed to happen, in which case it should be documented. Or if this is a bug?it only seems to happen in rare cases where the full body is send (first close) but there is an error reading the response (second close).
Here are the stack traces which both called
Close()
on the sameReadCloser
:The text was updated successfully, but these errors were encountered: