Skip to content
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

core,okhttp,netty,alts,testing: Plumb proxy resolved addr to transports #4137

Merged
merged 10 commits into from
Mar 12, 2018

Conversation

zpencer
Copy link
Contributor

@zpencer zpencer commented Feb 24, 2018

This PR has two commits, and the second commit has a lot of low
impact code churn due to an internal API cleanup.

First commit:
ProxyDetector should resolve proxy address and plumb results

ProxyDetector is now responsible for resolving the proxy's
`InetSocketAddress`, and `ProxyParameters` asserts that the address is
resolved. The results are plumbed through using a special subclass of
`SocketAddress`.

If a proxy should be used but the proxy can not be resolved, the
`DnsNameResolver` will re-attempt the resolution later.

Remove the unit test testing for unresolved proxy addresses, since
it's no longer applicable.

Second commit:
Plumb ProxiedInetSocketAddress down to transports

Do not extract the `ProxyParameters` field and pass it into
`ClientTransportFactory.newClientTransport`.

fixes #4029

final ProxyParameters proxy;
try {
proxy = proxyDetector.proxyFor(destination);
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just catch IOException?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (proxy != null) {
EquivalentAddressGroup server = new EquivalentAddressGroup(destination);
EquivalentAddressGroup server =
new EquivalentAddressGroup(new ProxiedInetSocketAddress(destination, proxy));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProxiedInetSocketAddress is weird, and it can't be internal long-term. Any NR should be able to support proxies.

The discussion about it should probably include @zhangkun83. (IIRC, the problem here is how should flattening by pick-first impact the attributes of the EquivalentAddressGroup.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProxiedInetSocketAddress was my suggestion. I don't see a problem making it public if we need to. Can you elaborate your concerns?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhangkun83 and I talked at length about this offline. It seems we're going to be mucking with how NameResolvers and LBs communicate again. That will need some other requirements to be gathered. But in the short term we want some sort of PairSocketAddress (I'm saying that name because it is obviously bad; we need a different name) that would contain (SocketAddress, Attr). It basically shoe-horns something similar to the deleted ResolvedServerInfo without a full redesign of the APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this imply EquivalentAddressGroup::getAddresses() would return a list of PairSocketAddress? Sounds like we will just commit to making this class public now, and reusing it later for NameResolvers+LBs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would continue to return a list of SocketAddress. No, we're not ready to make this public. There needs to be a longer-term design and that needs some investigation into requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, changed it to PairSocketAddress

@@ -205,6 +202,21 @@ public void run() {
}
}
}

private void rescheduleWithCause(Listener savedListener, Exception cause) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will cause some git conflicts with #4105. (It looks like it'll be unnecessary after that other PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and removed unnecessary rescheduling

@@ -147,8 +147,6 @@ void handleUncaughtThrowable(Throwable t) {
// Only null after channel is terminated. Must be assigned from the channelExecutor.
private NameResolver nameResolver;

private final ProxyDetector proxyDetector;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we should plumb the proxyDetector eventually through here to the Name Resolver. We shouldn't pass the proxyDetector is the constructor like we do now. We could pass it in as Attributes params.

(CC @zhangkun83, I wonder if we should revisit that params argument to the NameResolver and do something more similar to Params/Helper from LB. That can be later though.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will application provide ProxyDetector? Do we want NameResolvers to decide whether to use proxy or not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want proxies to make the final determination, but we should provide the detector. We shouldn't assume such information is global. There's #3957 for example.

ProxyDetector is now responsible for resolving the proxy's
`InetSocketAddress`, and `ProxyParameters` asserts that the address is
resolved. The results are plumbed through using a special subclass of
`SocketAddress`.

If a proxy should be used but the proxy can not be resolved, we the
`DnsNameResolver` will re-attempt the resolution later.

Remove the unit test testing for unresolved proxy addresses, since
it's no longer applicable.
Do not extract the `ProxyParameters` field and pass it into
`ClientTransportFactory.newClientTransport`.
- PairSocketAddress
- use correct DnsNameResolver error handling
- let ProxyDetector be passed in as getNameResolverParams
@@ -47,12 +49,17 @@ public DnsNameResolver newNameResolver(URI targetUri, Attributes params) {
Preconditions.checkArgument(targetPath.startsWith("/"),
"the path component (%s) of the target (%s) must start with '/'", targetPath, targetUri);
String name = targetPath.substring(1);
// We want to eventually let the ProxyDetector be passed in from ManagedChannel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of this change until ManagedChannelImpl is actually passing the value. It's small and it's more complex to do it half-way. It also makes an awkward test with testProxyDetectorSpecified. Do this change all-at-once (either now or later).


@VisibleForTesting
PairSocketAddress(SocketAddress address, Attributes attributes) {
this.address = address;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkNotNull for both arguments?

@zpencer zpencer merged commit 402c174 into grpc:master Mar 12, 2018
@zpencer zpencer deleted the plumb-proxy-resolved-addr branch March 12, 2018 18:15
@jjpet123
Copy link

jjpet123 commented Mar 22, 2018

Hi! @ejona86 @zpencer

Quick question, it is my understanding that this will fix the "UnresolvedAddressException" we hit in 1.90 when passing proxy hostnames to the system property "https.proxyHost" (we are NOT using GRPC_PROXY_EXP), is that right? Please confirm, thanks!

@zpencer
Copy link
Contributor Author

zpencer commented Mar 23, 2018

Yes, this PR fixes the unresolved address issue and allows you to use -Dhttps.proxyHost and optionally with a password via java.net.Authenticator.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plumb proxy address through Name Resolver
4 participants