Skip to content

Commit a8e921a

Browse files
author
Maksym Pavlenko
authored
Merge pull request containerd#10175 from dcantah/swap-to-newclient-grpc
Integration: Change to grpc.NewClient
2 parents f690928 + 9ecfac7 commit a8e921a

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

integration/main_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,7 @@ func RawRuntimeClient() (runtime.RuntimeServiceClient, error) {
656656
if err != nil {
657657
return nil, fmt.Errorf("failed to get dialer: %w", err)
658658
}
659-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
660-
defer cancel()
661-
conn, err := grpc.DialContext(ctx, addr,
659+
conn, err := grpc.NewClient(addr,
662660
grpc.WithTransportCredentials(insecure.NewCredentials()),
663661
grpc.WithContextDialer(dialer),
664662
)

integration/remote/remote_image.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ limitations under the License.
3333
package remote
3434

3535
import (
36-
"context"
3736
"errors"
3837
"fmt"
3938
"time"
@@ -62,10 +61,7 @@ func NewImageService(endpoint string, connectionTimeout time.Duration) (internal
6261
return nil, err
6362
}
6463

65-
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
66-
defer cancel()
67-
68-
conn, err := grpc.DialContext(ctx, addr,
64+
conn, err := grpc.NewClient(addr,
6965
grpc.WithTransportCredentials(insecure.NewCredentials()),
7066
grpc.WithContextDialer(dialer),
7167
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)),

integration/remote/remote_runtime.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ func NewRuntimeService(endpoint string, connectionTimeout time.Duration) (intern
7070
if err != nil {
7171
return nil, err
7272
}
73-
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
74-
defer cancel()
7573

76-
conn, err := grpc.DialContext(ctx, addr,
74+
conn, err := grpc.NewClient(addr,
7775
grpc.WithTransportCredentials(insecure.NewCredentials()),
7876
grpc.WithContextDialer(dialer),
7977
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)),

integration/remote/util/util_unix.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ package util
3636

3737
import (
3838
"context"
39+
"errors"
3940
"fmt"
4041
"net"
4142
"net/url"
@@ -99,10 +100,16 @@ func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, add
99100
return "", nil, err
100101
}
101102
if protocol != unixProtocol {
102-
return "", nil, fmt.Errorf("only support unix socket endpoint")
103+
return "", nil, errors.New("only support unix socket endpoint")
103104
}
104105

105-
return addr, dial, nil
106+
// Use passthrough as the scheme so it allows us to use our custom dialer:
107+
//
108+
// "grpc.Dial uses "passthrough" as the default name resolver for backward compatibility while grpc.NewClient
109+
// uses "dns" as its default name resolver. This subtle difference is important to legacy systems that also
110+
// specified a custom dialer and expected it to receive the target string directly."
111+
// https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#the-wrong-way-grpcdial
112+
return fmt.Sprintf("passthrough:///%s", addr), dial, nil
106113
}
107114

108115
func dial(ctx context.Context, addr string) (net.Conn, error) {

integration/remote/util/util_windows.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ package util
3434

3535
import (
3636
"context"
37+
"errors"
3738
"fmt"
3839
"net"
3940
"net/url"
@@ -75,6 +76,13 @@ func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, add
7576
return "", nil, err
7677
}
7778

79+
// Use passthrough as the scheme so it allows us to use our custom dialer:
80+
//
81+
// "grpc.Dial uses "passthrough" as the default name resolver for backward compatibility while grpc.NewClient
82+
// uses "dns" as its default name resolver. This subtle difference is important to legacy systems that also
83+
// specified a custom dialer and expected it to receive the target string directly."
84+
// https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#the-wrong-way-grpcdial
85+
addr = fmt.Sprintf("passthrough:///%s", addr)
7886
if protocol == tcpProtocol {
7987
return addr, tcpDial, nil
8088
}
@@ -83,7 +91,7 @@ func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, add
8391
return addr, npipeDial, nil
8492
}
8593

86-
return "", nil, fmt.Errorf("only support tcp and npipe endpoint")
94+
return "", nil, errors.New("only support tcp and npipe endpoint")
8795
}
8896

8997
func tcpDial(ctx context.Context, addr string) (net.Conn, error) {

0 commit comments

Comments
 (0)