Open DavidArchibald opened 3 months ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Any request with a body will do, e.g. curl http://localhost:8080 -d '{}'
. Python isn't necessary to make the request.
Looks like the concurrent read happens when the server tries to drain the body in preparation for reusing the connection. Adding either of the below avoids the panic:
defer r.Body.Close()
to the handler-H 'connection: close'
from the client sidecc @neild
marking the connection non-reusable with -H 'connection: close' from the client side
That makes sense. I can confirm that the other clients I tried were adding connection: close
to their headers. This is why I ended up including Python in my attempt at minimum reproduction because I couldn't figure out how to distill it down.
Any request with a body will do, e.g.
curl http://localhost:8080 -d '{}'
. Python isn't necessary to make the request.Looks like the concurrent read happens when the server tries to drain the body in preparation for reusing the connection. Adding either of the below avoids the panic:
defer r.Body.Close()
to the handler- marking the connection non-reusable with
-H 'connection: close'
from the client side
@seankhliao When the server has EnableFullDuplex
enabled, should it be specified in the documentation that req.Body.Close()
needs to be called explicitly, since the transport no longer handles closing it?
@neild Could you share your thoughts on this?
Go version
go version go1.22.5 linux/amd64
Output of
go env
in your module/workspace:What did you do?
While I encountered this with a full fledged server I simplified it down to this script:
I then narrowed down the issue to when I make a request like so:
I don't have this problem when I try to reproduce the issue in Postman or craft the request myself, even when I make it obstensibly identical. Likely because of differences in client behaviours.
What did you see happen?
The program panicked with this result:
What did you expect to see?
I expected no panic. Perhaps there's a reason that enabling
EnableFullDuplex
is bad in a handler like this but I couldn't find any documentation that suggested this would be harmful.I could manage to get this panic to go away by moving this handler a bit later into the actual router I have but this seems to indicate to me that it's actually a race condition or something.