From 707e298f55ef081e8a6001502989a55cb02c29e5 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Mon, 16 Nov 2020 14:34:08 -0800 Subject: [PATCH] internal: fix net.Dial fail without IP (#4037) --- test/authority_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/authority_test.go b/test/authority_test.go index af289bc69ed0..e8307fee225d 100644 --- a/test/authority_test.go +++ b/test/authority_test.go @@ -176,7 +176,12 @@ func (s) TestColonPortAuthority(t *testing.T) { authorityMu.Unlock() // ss.Start dials, but not the ":[port]" target that is being tested here. // Dial again, with ":[port]" as the target. - cc, err := grpc.Dial(":"+port, grpc.WithInsecure()) + // + // Append "localhost" before calling net.Dial, in case net.Dial on certain + // platforms doesn't work well for address without the IP. + cc, err := grpc.Dial(":"+port, grpc.WithInsecure(), grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "tcp", "localhost"+addr) + })) if err != nil { t.Fatalf("grpc.Dial(%q) = %v", ss.target, err) }