From 6b5efba83b2aa68b522ebfe73d3fed8e18a59429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 7 Mar 2025 16:02:01 +0100 Subject: [PATCH] client: Respect `client.WithTimeout` option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the gRPC client dialer not using the timeout passed by the containerd client timeout option. Commit 63b4688175 replaced the usage of deprecated `grpc.DialContext` with `grpc.NewClient`. However, the `dialer.ContextDialer` relied on the context deadline to propagate the timeout: https://github.com/containerd/containerd/blob/388fb336b0a458e2cf64212072743e622a3f44c7/vendor/google.golang.org/grpc/clientconn.go#L216 This assumption is now broken, because `grpc.NewClient` doesn't do any initial connection and defers it to the first RPC usage. This commit passes the timeout via the `MinConnectTimeout` grpc connection param, which will be applied to **every** connection attempt (not just the first). Signed-off-by: Paweł Gronowski --- client/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index c58459b21..8a19d3307 100644 --- a/client/client.go +++ b/client/client.go @@ -129,7 +129,8 @@ func New(address string, opts ...Opt) (*Client, error) { backoffConfig := backoff.DefaultConfig backoffConfig.MaxDelay = copts.timeout connParams := grpc.ConnectParams{ - Backoff: backoffConfig, + Backoff: backoffConfig, + MinConnectTimeout: copts.timeout, } gopts := []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()),