mirror of
https://github.com/golang/go.git
synced 2026-06-26 10:50:23 +00:00
net/http: fix hang in TestTransportClosesBodyOnError/h3
TestTransportClosesBodyOnError could hang intermittently on HTTP/3 when the transport encounters an error too early while reading the request body. In HTTP/3 over QUIC, a stream reset is abrupt and can cause the server to skip invoking the handler if the reset arrives before headers are fully processed. This will leave the test waiting indefinitely for the server handler to run, which will never happen. Fix this issue by adding "Expect: 100-continue" header to the request. This guarantees that the server handler has started before the client attempts to send the request body and encounters the error. For #78737 Change-Id: I56092e78973f067eab3309231956305f6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/777740 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
81f747893d
commit
c22f92a751
1 changed files with 8 additions and 0 deletions
|
|
@ -4168,6 +4168,14 @@ func testTransportClosesBodyOnError(t *testing.T, mode testMode) {
|
|||
return nil
|
||||
}),
|
||||
})
|
||||
// Use 100-continue to ensure the server handler starts before the client
|
||||
// delivers the error. Otherwise, an early error might cause the server to
|
||||
// skip the handler, causing this test to hang waiting for readBody.
|
||||
// This happens very rarely on HTTP/3 because QUIC stream resets are abrupt
|
||||
// and can terminate the stream before headers are processed, whereas
|
||||
// TCP-based HTTP/1 and HTTP/2 typically deliver headers in order before
|
||||
// the reset signal.
|
||||
req.Header.Set("Expect", "100-continue")
|
||||
res, err := c.Do(req)
|
||||
if res != nil {
|
||||
defer res.Body.Close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue