From d47d0dd702a1efa47a3fdd153505b98d9868610a Mon Sep 17 00:00:00 2001 From: Sebastian Wicki Date: Tue, 16 Apr 2024 14:56:37 +0200 Subject: [PATCH] shared client: Fix global timeout not being respected This fixes a bug where the shared client did not respect `c.Client.Timeout`, resulting in DNS requests timing out too soon. A per Go docs, `Client.Timeout` is supposed to also apply to the write timeout. This is implemented in the regular client by using `Client.getTimeoutForRequest` to determine the actual timeout. This commit adapts the shared client code to do the same. Signed-off-by: Sebastian Wicki --- shared_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared_client.go b/shared_client.go index ae1c386a1..0b8bbeec7 100644 --- a/shared_client.go +++ b/shared_client.go @@ -291,7 +291,7 @@ func (c *SharedClient) ExchangeSharedContext(ctx context.Context, m *Msg) (r *Ms // This request keeps 'c.requests' open; sending a request may hang indefinitely if // the handler happens to quit at the same time. Use ctx.Done to avoid this. - timeout := c.Client.writeTimeout() + timeout := c.getTimeoutForRequest(c.Client.writeTimeout()) ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() respCh := make(chan sharedClientResponse)