daemon: Fix giving up too early while connecting to containerd socket

Explicitly set the gRPC connection params to take the timeout into
account to workaround the containerd v2 client not passing down the
stack.

containerd v2 replaced usages of deprecated gRPC functions but didn't
pass the timeout to the actual dial connection options.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-03-07 18:15:17 +01:00
parent c90cbc89c0
commit df519e9e1a
2 changed files with 17 additions and 4 deletions

View File

@@ -901,13 +901,17 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
return nil, err
}
const connTimeout = 60 * time.Second
// Set the max backoff delay to match our containerd.WithTimeout(),
// aligning with how containerd client's defaults sets this;
// https://github.com/containerd/containerd/blob/v2.0.2/client/client.go#L129-L136
backoffConfig := backoff.DefaultConfig
backoffConfig.MaxDelay = 60 * time.Second
backoffConfig.MaxDelay = connTimeout
connParams := grpc.ConnectParams{
Backoff: backoffConfig,
// TODO: Remove after https://github.com/containerd/containerd/pull/11508
MinConnectTimeout: connTimeout,
}
gopts := []grpc.DialOption{
// ------------------------------------------------------------------
@@ -931,11 +935,15 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
}
if cfgStore.ContainerdAddr != "" {
log.G(ctx).WithFields(log.Fields{
"address": cfgStore.ContainerdAddr,
"timeout": connTimeout,
}).Info("Creating a containerd client")
d.containerdClient, err = containerd.New(
cfgStore.ContainerdAddr,
containerd.WithDefaultNamespace(cfgStore.ContainerdNamespace),
containerd.WithDialOpts(gopts),
containerd.WithTimeout(60*time.Second),
containerd.WithTimeout(connTimeout),
)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", cfgStore.ContainerdAddr)
@@ -950,7 +958,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
cfgStore.ContainerdAddr,
containerd.WithDefaultNamespace(cfgStore.ContainerdPluginNamespace),
containerd.WithDialOpts(gopts),
containerd.WithTimeout(60*time.Second),
containerd.WithTimeout(connTimeout),
)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", cfgStore.ContainerdAddr)

View File

@@ -280,14 +280,19 @@ func (r *remote) monitorDaemon(ctx context.Context) {
continue
}
const connTimeout = 60 * time.Second
client, err = containerd.New(
r.GRPC.Address,
containerd.WithTimeout(60*time.Second),
containerd.WithTimeout(connTimeout),
containerd.WithDialOpts([]grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(dialer.ContextDialer),
grpc.WithUnaryInterceptor(grpcerrors.UnaryClientInterceptor),
grpc.WithStreamInterceptor(grpcerrors.StreamClientInterceptor),
grpc.WithConnectParams(grpc.ConnectParams{
// TODO: Remove after https://github.com/containerd/containerd/pull/11508
MinConnectTimeout: connTimeout,
}),
}),
)
if err != nil {