From 038ec9dcdd0455fe518e6e120f057c0d3ceb5cbd Mon Sep 17 00:00:00 2001 From: Taction Date: Tue, 28 May 2024 01:19:53 +0800 Subject: [PATCH] http2: do not retry dial if request context canceled When request context is canceled or expired, do not retry on dialing to the server. --- http2/client_conn_pool.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/http2/client_conn_pool.go b/http2/client_conn_pool.go index 780968d6c1..2eea70970e 100644 --- a/http2/client_conn_pool.go +++ b/http2/client_conn_pool.go @@ -300,6 +300,10 @@ func shouldRetryDial(call *dialCall, req *http.Request) bool { // from this request. return false } + if req.Context().Err() != nil { + // If the request is canceled or expired, should not retry. + return false + } if !errors.Is(call.err, context.Canceled) && !errors.Is(call.err, context.DeadlineExceeded) { // If the call error is not because of a context cancellation or a deadline expiry, // the dial should not be retried.