]> Cypherpunks repositories - gostls13.git/commit
net/http: simplify HTTP/1 request cancelation
authorDamien Neil <dneil@google.com>
Sat, 2 Dec 2023 00:26:14 +0000 (16:26 -0800)
committerDamien Neil <dneil@google.com>
Thu, 16 May 2024 15:57:17 +0000 (15:57 +0000)
commit505000b2d38c4c93aa7d30e82c61b76a6925b4e9
treec605bc4049ca5ac08bd967f278e0049052234839
parent33d725e5758bf1fea62e6c77fc70b57a828a49f5
net/http: simplify HTTP/1 request cancelation

HTTP requests have three separate user cancelation signals:

Transport.CancelRequest
Request.Cancel
Request.Context()

In addition, a request can be canceled due to errors.

The Transport keeps a map of all in-flight requests,
with an associated func to run if CancelRequest is
called. Confusingly, this func is *not* run if
Request.Cancel is closed or the request context expires.

The map of in-flight requests is also used to communicate
between roundTrip and readLoop. In particular, if readLoop
reads a response immediately followed by an EOF, it may
send racing signals to roundTrip: The connection has
closed, but also there is a response available.
This race is resolved by readLoop communicating through
the request map that this request has successfully
completed.

This CL refactors all of this.

In-flight requests now have a context which is canceled
when any of the above cancelation events occurs.

The map of requests to cancel funcs remains, but is
used strictly for implementing Transport.CancelRequest.
It is not used to communicate information about the
state of a request.

Change-Id: Ie157edc0ce35f719866a0a2cb0e70514fd119ff8
Reviewed-on: https://go-review.googlesource.com/c/go/+/546676
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/net/http/transport.go
src/net/http/transport_internal_test.go