client: Respect client.WithTimeout option

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:

388fb336b0/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 <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2025-03-07 16:02:01 +01:00 committed by k8s-infra-cherrypick-robot
parent 76db0585af
commit 6b5efba83b

View File

@ -130,6 +130,7 @@ func New(address string, opts ...Opt) (*Client, error) {
backoffConfig.MaxDelay = copts.timeout
connParams := grpc.ConnectParams{
Backoff: backoffConfig,
MinConnectTimeout: copts.timeout,
}
gopts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),