-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
internal/delegatingresolver: avoid proxy if networktype of target address is not tcp #8215
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8215 +/- ##
==========================================
- Coverage 82.17% 82.17% -0.01%
==========================================
Files 410 410
Lines 40236 40405 +169
==========================================
+ Hits 33065 33203 +138
- Misses 5822 5842 +20
- Partials 1349 1360 +11
🚀 New features to boost your workflow:
|
if len(curState.Endpoints) != 0 { | ||
networkType, ok = networktype.Get(curState.Endpoints[0].Addresses[0]) | ||
} else { | ||
networkType, ok = networktype.Get(curState.Addresses[0]) | ||
} |
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.
Here we're making an assumption that the network type of the first address of the endpoint is the same the address type of all remaining addresses. This may be true for most real-world usecases, but it isn't a requirement specified in the resolver API. It should not be too difficult to avoid proxying on a per-address basis. There are two places below where we do the following, one for resolver.State.Addresses
and once for resolver.State.Endpoints
:
proxyattributes.Set(proxyAddr, proxyattributes.Options{
User: r.proxyURL.User,
ConnectAddr: targetAddr.Addr,
})
We can refactor this into a method that takes in the target address and proxy address and returns the combined address.
fn (r *delegatingResolver) combineAddresses(targetAddr, proxyAddr resolver.Address) resolver.Address {
if networktype.Get(targetAddr) != "tcp" {
return targetAddr
}
return proxyattributes.Set(proxyAddr, proxyattributes.Options{
User: r.proxyURL.User,
ConnectAddr: targetAddr.Addr,
})
}
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.
The above comment end up adding duplicate addresses in the loop on targetResolverState.Endpoints
. We will probably need to invert the loop on r.proxyAddrs
and endpt.Addresses
and break early:
for _, endpt := range (*r.targetResolverState).Endpoints {
var addrs []resolver.Address
for _, targetAddr := range endpt.Addresses {
if networktype.Get(targetAddr) != "tcp" {
addrs = append(addrs, targetAddr)
continue
}
for _, proxyAddr := range r.proxyAddrs {
addrs = append(addrs, proxyattributes.Set(proxyAddr, proxyattributes.Options{
User: r.proxyURL.User,
ConnectAddr: targetAddr.Addr,
}))
}
}
endpoints = append(endpoints, resolver.Endpoint{Addresses: addrs})
}
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.
Right, done ! Also added a check in beginning , if there is not address with network type TCP , we do not wait for proxy update and just update the cc state.
Please also fix the format of the release notes. |
if networkType, ok := networktype.Get(addr); !ok || networkType == "tcp" { | ||
isTCP = true | ||
break | ||
} |
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.
Out here we're assuming !ok
to be the same of tcp
. However, the old code in the dialer used to parse the address string when !ok
to determine the network type, we should probably maintain the same behaviour.
grpc-go/internal/transport/http2_client.go
Lines 177 to 182 in 172fc5b
if !ok { | |
networkType, address = parseDialTarget(address) | |
} | |
if networkType == "tcp" && useProxy { | |
return proxyDial(ctx, address, grpcUA) | |
} |
if networkType, ok := networktype.Get(addr); !ok || networkType == "tcp" || isTCP { | ||
isTCP = true | ||
break | ||
} |
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.
I think the code will be simpler if we refactor finding a TCP address in a helper function. The helper function can return early instead of keeping track of a isTCP
boolean and breaking out of nested loops.
} else { | ||
addresses = append(addresses, proxyattributes.Set(proxyAddr, proxyattributes.Options{ | ||
User: r.proxyURL.User, | ||
ConnectAddr: targetAddr.Addr, | ||
})) | ||
} |
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.
nit: You can use continue
in the if
block to avoid indenting the else
block.
} else { | ||
for _, proxyAddr := range r.proxyAddrs { | ||
addrs = append(addrs, proxyattributes.Set(proxyAddr, proxyattributes.Options{ | ||
User: r.proxyURL.User, | ||
ConnectAddr: targetAddr.Addr, | ||
})) | ||
} | ||
} |
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.
nit: You can use continue
in the if
block to avoid indenting the else
block.
Fixes: #8207
RELEASE NOTES: