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

net/http: sniffing for non-zero GET request body is broken #47568

Closed
neild opened this issue Aug 6, 2021 · 2 comments
Closed

net/http: sniffing for non-zero GET request body is broken #47568

neild opened this issue Aug 6, 2021 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@neild
Copy link
Contributor

neild commented Aug 6, 2021

When making a request which usually lacks a response body (GET, HEAD, DELETE, etc.), if the Request.Body is non-nil, the content length is not set, and Transfer-Encoding: chunked is not set, we attempt to read one byte from the body before sending the request. If the read succeeds within 200ms and indicates a zero-length body, we set Request.Body = nil.

If the read takes more than 200ms, we set Transfer-Encoding: chunked and proceed.

See: https://go.googlesource.com/go/+/refs/heads/master/src/net/http/transfer.go#191

The latter path (when the probe does not complete within 200ms) is broken when the body is not zero-length.

In this path, we replace Request.Body with io.MultiReader(finishAsyncByteRead{t}, t.Body). finishAsyncByteRead.Read does not return io.EOF after reading the initial byte, so the io.MultiReader retries the read, which never completes.

https://go.googlesource.com/go/+/refs/heads/master/src/net/http/transfer.go#1066

The impact is that sending a request can hang when all of the following apply:

  • The request method is one of GET, HEAD, DELETE, OPTIONS, PROPFIND, or SEARCH.
  • The Request.Body is non-nil.
  • The content length is not set, or is set to -1.
  • Transfer-Encoding: chunked is not set.
  • The request body does not respond to a read within 200ms.

Thanks to @EdSchouten for identifying this problem in CL 328711.

@gopherbot
Copy link

Change https://golang.org/cl/340256 mentions this issue: net/http: fix hang in probing for a zero-length request body

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 7, 2021
@born2ngopi
Copy link

is the request like this @neild ?

curl localhost:9999 --request GET --data '{"name":"abcd"}' --header "Content-Length: -1"

`

@golang golang locked and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants