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

x/net/http2: h2c requests can't be sent when *http.Request.Close is true #67671

Closed
WeidiDeng opened this issue May 28, 2024 · 3 comments
Closed
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@WeidiDeng
Copy link

Go version

go version go1.22.0 windows/amd64

Output of go env in your module/workspace:

not relevant

What did you do?

Setting *http.Request.Close to true to disable persistent connections in proxyprotocol reverse proxy scenarios. This comes from this issue.

It can be reproduced,

server:

	server := httptest.NewUnstartedServer(h2c.NewHandler(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
		_, _ = io.WriteString(writer, request.Proto)
	}), new(http2.Server)))
	fmt.Println(server.Listener.Addr().String())
	server.Start()
	select {}

client:

func TestSingle(t *testing.T) {
	h2t := &http2.Transport{
		DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
			return (&net.Dialer{}).DialContext(ctx, network, addr)
		},
		AllowHTTP: true,
	}
	req, _ := http.NewRequest("GET", "http://127.0.0.1:51905", nil)
	req.Close = true
	for range 100 {
		resp, err := h2t.RoundTrip(req)
		if err != nil {
			t.Error(err)
		}
		_ = resp.Write(io.Discard)
	}
}

The error is http2: client conn not usable.

What did you see happen?

It works for https request but not for h2c requests.

What did you expect to see?

It should work in both cases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/588635 mentions this issue: http2: check if transport allows h2c before determining if a request has been sent

@mknyszek mknyszek added this to the Unreleased milestone Jun 3, 2024
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 3, 2024
@mknyszek
Copy link
Contributor

mknyszek commented Jun 3, 2024

CC @neild

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/591275 mentions this issue: http2: avoid Transport hang with Connection: close and AllowHTTP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants