diff --git a/clientconn.go b/clientconn.go index 314addcaa1cb..91a3b605c931 100644 --- a/clientconn.go +++ b/clientconn.go @@ -1870,7 +1870,12 @@ func (cc *ClientConn) determineAuthority() error { // the channel authority given the user's dial target. For resolvers // which don't implement this interface, we will use the endpoint from // "scheme://authority/endpoint" as the default authority. - cc.authority = endpoint + + // Path escape the endpoint to handle use cases where the endpoint + // might not be a valid authority by default. + // For example an endpoint which has multiple paths like + // 'a/b/c', which is not a valid authority by default. + cc.authority = url.PathEscape(endpoint) } channelz.Infof(logger, cc.channelzID, "Channel authority set to %q", cc.authority) return nil diff --git a/test/authority_test.go b/test/authority_test.go index 44095a23a2fe..a4d481f24f92 100644 --- a/test/authority_test.go +++ b/test/authority_test.go @@ -126,7 +126,7 @@ var authorityTests = []authorityTest{ name: "UnixPassthrough", address: "/tmp/sock.sock", target: "passthrough:///unix:///tmp/sock.sock", - authority: "unix:///tmp/sock.sock", + authority: "unix:%2F%2F%2Ftmp%2Fsock.sock", dialTargetWant: "unix:///tmp/sock.sock", }, {