-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client: fix "unix" scheme handling for some corner cases #4021
Changes from 5 commits
06c753c
b9b89fd
8fbca88
62ccdd1
e3221bd
69696f9
ecbb2d3
7472fbc
e602bd7
894d568
72a6753
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,17 +70,21 @@ func TestParseTargetString(t *testing.T) { | |
// If we can only parse part of the target. | ||
{targetStr: "://", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "://"}}, | ||
{targetStr: "unix://domain", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "unix://domain"}}, | ||
{targetStr: "unix://a/b/c", want: resolver.Target{Scheme: "unix", Authority: "a", Endpoint: "b/c"}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's "/b/c" now due to the revert of the +"/" change. |
||
{targetStr: "a:b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a:b"}}, | ||
{targetStr: "a/b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a/b"}}, | ||
{targetStr: "a:/b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a:/b"}}, | ||
{targetStr: "a//b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a//b"}}, | ||
{targetStr: "a://b", want: resolver.Target{Scheme: "", Authority: "", Endpoint: "a://b"}}, | ||
|
||
// Unix cases without custom dialer. | ||
// unix:[local_path] and unix:[/absolute] have different behaviors with | ||
// a custom dialer, to prevent behavior changes with custom dialers. | ||
{targetStr: "unix:domain", want: resolver.Target{Scheme: "unix", Authority: "", Endpoint: "domain"}, wantWithDialer: resolver.Target{Scheme: "", Authority: "", Endpoint: "unix:domain"}}, | ||
{targetStr: "unix:/domain", want: resolver.Target{Scheme: "unix", Authority: "", Endpoint: "/domain"}, wantWithDialer: resolver.Target{Scheme: "", Authority: "", Endpoint: "unix:/domain"}}, | ||
// unix:[local_path], unix:[/absolute], and unix://[/absolute] have different | ||
// behaviors with a custom dialer, to prevent behavior changes with custom dialers. | ||
{targetStr: "unix:a/b/c", want: resolver.Target{Scheme: "unix", Authority: "", Endpoint: "a/b/c"}, wantWithDialer: resolver.Target{Scheme: "", Authority: "", Endpoint: "unix:a/b/c"}}, | ||
{targetStr: "unix:/a/b/c", want: resolver.Target{Scheme: "unix", Authority: "", Endpoint: "/a/b/c"}, wantWithDialer: resolver.Target{Scheme: "", Authority: "", Endpoint: "unix:/a/b/c"}}, | ||
{targetStr: "unix:///a/b/c", want: resolver.Target{Scheme: "unix", Authority: "", Endpoint: "/a/b/c"}, wantWithDialer: resolver.Target{Scheme: "unix", Authority: "", Endpoint: "a/b/c"}}, | ||
|
||
{targetStr: "passthrough:///unix:///a/b/c", want: resolver.Target{Scheme: "passthrough", Authority: "", Endpoint: "unix:///a/b/c"}}, | ||
} { | ||
got := ParseTarget(test.targetStr, false) | ||
if got != test.want { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,17 +139,24 @@ type http2Client struct { | |
} | ||
|
||
func dial(ctx context.Context, fn func(context.Context, string) (net.Conn, error), addr resolver.Address, useProxy bool, grpcUA string) (net.Conn, error) { | ||
networkType := "tcp" | ||
address := addr.Addr | ||
n, ok := networktype.Get(addr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this change. |
||
if fn != nil { | ||
return fn(ctx, addr.Addr) | ||
if ok && n == "unix" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got rid of redundant ok |
||
return fn(ctx, "unix:///"+address) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This deserves a comment. Something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this comment. |
||
} | ||
return fn(ctx, address) | ||
} | ||
networkType := "tcp" | ||
if n, ok := networktype.Get(addr); ok { | ||
if ok { | ||
networkType = n | ||
} else { | ||
networkType, address = parseDialTarget(address) | ||
} | ||
if networkType == "tcp" && useProxy { | ||
return proxyDial(ctx, addr.Addr, grpcUA) | ||
return proxyDial(ctx, address, grpcUA) | ||
} | ||
return (&net.Dialer{}).DialContext(ctx, networkType, addr.Addr) | ||
return (&net.Dialer{}).DialContext(ctx, networkType, address) | ||
} | ||
|
||
func isTemporary(err error) bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this need to change? I think this can be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this.