aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/export_test.go
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2024-04-04 11:01:28 -0700
committerDamien Neil <dneil@google.com>2024-04-17 21:11:57 +0000
commit334ce510046ad30b1be466634cf313aad3040892 (patch)
treee60f4653ddac8473abf679a3ead5fbf59d0d8d09 /src/net/http/export_test.go
parent4742c52e101ecf4aacebe5148a1cb172bdadb1d4 (diff)
downloadgo-334ce510046ad30b1be466634cf313aad3040892.tar.xz
net/http: don't cancel Dials when requests are canceled
Currently, when a Transport creates a new connection for a request, it uses the request's Context to make the Dial. If a request times out or is canceled before a Dial completes, the Dial is canceled. Change this so that the lifetime of a Dial call is not bound by the request that originated it. This change avoids a scenario where a Transport can start and then cancel many Dial calls in rapid succession: - Request starts a Dial. - A previous request completes, making its connection available. - The new request uses the now-idle connection, and completes. - The request Context is canceled, and the Dial is aborted. Fixes #59017 Change-Id: I996ffabc56d3b1b43129cbfd9b3e9ea7d53d263c Reviewed-on: https://go-review.googlesource.com/c/go/+/576555 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/net/http/export_test.go')
-rw-r--r--src/net/http/export_test.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go
index 8a6f4f192f..56ebda180b 100644
--- a/src/net/http/export_test.go
+++ b/src/net/http/export_test.go
@@ -86,6 +86,14 @@ func SetPendingDialHooks(before, after func()) {
func SetTestHookServerServe(fn func(*Server, net.Listener)) { testHookServerServe = fn }
+func SetTestHookProxyConnectTimeout(t *testing.T, f func(context.Context, time.Duration) (context.Context, context.CancelFunc)) {
+ orig := testHookProxyConnectTimeout
+ t.Cleanup(func() {
+ testHookProxyConnectTimeout = orig
+ })
+ testHookProxyConnectTimeout = f
+}
+
func NewTestTimeoutHandler(handler Handler, ctx context.Context) Handler {
return &timeoutHandler{
handler: handler,