From 80101933c007185c7a72efb3a377482b2bb70246 Mon Sep 17 00:00:00 2001 From: Cassian433 Date: Thu, 8 Oct 2026 12:34:41 +0530 Subject: [PATCH] fix: bound doh dials so ones the query gave up on cannot pile up (#3274) --- dns/doh.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dns/doh.go b/dns/doh.go index 690973f37..b56d8ffd4 100644 --- a/dns/doh.go +++ b/dns/doh.go @@ -383,10 +383,17 @@ func (doh *dnsOverHTTPS) createClient(ctx context.Context) (*http.Client, error) // HTTP3 is enabled in the upstream options). If this attempt is successful, // it returns an HTTP3 transport, otherwise it returns the H1/H2 transport. func (doh *dnsOverHTTPS) createTransport(ctx context.Context) (t http.RoundTripper, err error) { + // http.Transport dials in a context detached from the request, so a dial + // that the query has given up on must still end on its own. transport := &http.Transport{ DisableCompression: true, - DialContext: doh.dialer.DialContext, - IdleConnTimeout: transportDefaultIdleConnTimeout, + DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + ctx, cancel := context.WithTimeout(ctx, dialTimeout) + defer cancel() + return doh.dialer.DialContext(ctx, network, addr) + }, + IdleConnTimeout: transportDefaultIdleConnTimeout, + TLSHandshakeTimeout: dialTimeout, } if doh.url.Scheme == "http" {