diff --git a/examples/features/unix_abstract/server/main.go b/examples/features/unix_abstract/server/main.go index 4ef4ff5b763..7013466b491 100644 --- a/examples/features/unix_abstract/server/main.go +++ b/examples/features/unix_abstract/server/main.go @@ -51,7 +51,7 @@ func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.Echo func main() { flag.Parse() netw := "unix" - socketAddr := fmt.Sprintf("\x00%v", *addr) + socketAddr := fmt.Sprintf("@%v", *addr) lis, err := net.Listen(netw, socketAddr) if err != nil { log.Fatalf("net.Listen(%q, %q) failed: %v", netw, socketAddr, err) diff --git a/internal/resolver/unix/unix.go b/internal/resolver/unix/unix.go index 20852e59df2..7f1a702cacb 100644 --- a/internal/resolver/unix/unix.go +++ b/internal/resolver/unix/unix.go @@ -49,8 +49,9 @@ func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, _ resolv } addr := resolver.Address{Addr: endpoint} if b.scheme == unixAbstractScheme { - // prepend "\x00" to address for unix-abstract - addr.Addr = "\x00" + addr.Addr + // We can not prepend \0 as c++ gRPC does, as in Golang '@' is used to signify we do + // not want trailing \0 in address. + addr.Addr = "@" + addr.Addr } cc.UpdateState(resolver.State{Addresses: []resolver.Address{networktype.Set(addr, "unix")}}) return &nopResolver{}, nil diff --git a/test/authority_test.go b/test/authority_test.go index 452b896eebf..8148cd2347e 100644 --- a/test/authority_test.go +++ b/test/authority_test.go @@ -125,10 +125,10 @@ var authorityTests = []authorityTest{ }, { name: "UnixAbstract", - address: "\x00abc efg", + address: "@abc efg", target: "unix-abstract:abc efg", authority: "localhost", - dialTargetWant: "\x00abc efg", + dialTargetWant: "unix:@abc efg", }, } @@ -155,9 +155,7 @@ func (s) TestUnixCustomDialer(t *testing.T) { if address != test.dialTargetWant { return nil, fmt.Errorf("expected target %v in custom dialer, instead got %v", test.dialTargetWant, address) } - if !strings.HasPrefix(test.target, "unix-abstract:") { - address = address[len("unix:"):] - } + address = address[len("unix:"):] return (&net.Dialer{}).DialContext(ctx, "unix", address) } runUnixTest(t, test.address, test.target, test.authority, dialer)