Merge pull request #7189 from zouyee/ctx

This commit is contained in:
Fu Wei
2022-07-22 11:09:02 +08:00
committed by GitHub

View File

@@ -17,6 +17,7 @@
package ttrpcutil
import (
"context"
"errors"
"fmt"
"sync"
@@ -42,7 +43,9 @@ type Client struct {
// NewClient returns a new containerd TTRPC client that is connected to the containerd instance provided by address
func NewClient(address string, opts ...ttrpc.ClientOpts) (*Client, error) {
connector := func() (*ttrpc.Client, error) {
conn, err := dialer.Dialer(address, ttrpcDialTimeout)
ctx, cancel := context.WithTimeout(context.Background(), ttrpcDialTimeout)
defer cancel()
conn, err := dialer.ContextDialer(ctx, address)
if err != nil {
return nil, fmt.Errorf("failed to connect: %w", err)
}