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: lookup TXT records when doing name resolution #2912

Merged
merged 8 commits into from
Apr 20, 2017

Conversation

carl-mastrangelo
Copy link
Contributor

No description provided.


/**
* A resolver that uses the JNDI interface. This class is capable of looking up both addresses
* and text records, but does not provide ordering guarantees. When the {@link JdkResolver} is
Copy link
Member

Choose a reason for hiding this comment

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

What? Why would JdkResolver be unavailable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might not be prefered. I don't think it can use nsAuthority, while the jndi one can. Someone might prefer the latter behavior.

Removed anyways.

import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.naming.NamingEnumeration;
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem like Android has javax.naming. Or at least the older ones don't. Have you tested on Android?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I saw the DnsContextFactory, which would imply that it does, but I also see things like this though: https://issues.apache.org/jira/browse/LOG4J2-703

So that may be newer versions have it. But I also didn't see javax.naming at https://developer.android.com/reference/packages.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it is absent. Progaurd complains about refs to missing javax.naming classes, but not the com.sun ones. I think if I check for both, it will properly disable itself.

@VisibleForTesting
static final class JndiResolver extends DelegateResolver {

private static final String[] rrTypes = new String[]{"A", "AAAA", "TXT"};
Copy link
Member

Choose a reason for hiding this comment

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

Can we just request TXT? You mentioning that ANY was used makes me nervous, and it would be rare to use the A and AAAA here. Let's just KISS and only query for what we need.

static final class CompositeResolver extends DelegateResolver {

private final DelegateResolver jdkResovler;
@Nullable private final DelegateResolver jndiResovler;
Copy link
Member

Choose a reason for hiding this comment

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

Make jndiResolver required? It seems you only use this if it is available.

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.

I feel like you are pushing into premature simplification. This code was very easy to modify to accept results from other, future resolvers, but now it is going to be harder.

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

This is looking reasonable, but until the TXT is used for something, I'm not sure we want to do the I/O. Maybe we can have a static flag (like in DnsNameResolver) that enables the feature and it is off by default?

try {
inetAddrs = getAllByName(host);
} catch (UnknownHostException e) {
resolvedInetAddrs = delegateResolver.resolve(host);
Copy link
Member

Choose a reason for hiding this comment

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

So the TXT doesn't go anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently No. There are no consumers yet.

private static final String[] rrTypes = new String[]{"TXT"};

@Override
ResolutionResults resolve(String host) throws NamingException {
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to catch any exceptions from this, so that a failure to get TXT doesn't hose everything?

We may want to discuss with others what should happen if we get A/AAAA but have I/O errors durring TXT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it, but it should be fairly loud. Not honoring the service config if present is something a user would want to fix. It shouldn't reach this point if the JNDI resolver isn't present.

@carl-mastrangelo
Copy link
Contributor Author

PTAL

* in turn calls into libc which sorts addresses in order of reachability.
*/
@VisibleForTesting
static final class JdkResolver extends DelegateResolver {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be just a singleton object.

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

@ejona86
Copy link
Member

ejona86 commented Apr 20, 2017

@carl-mastrangelo, what about my "but until the TXT is used for something, I'm not sure we want to do the I/O" comment?

@carl-mastrangelo
Copy link
Contributor Author

@ejona86 good point. I added a boolean to disable it. It won't see any any actual usage outside of a test.

@carl-mastrangelo carl-mastrangelo merged commit b7833da into grpc:master Apr 20, 2017
@carl-mastrangelo carl-mastrangelo deleted the dns branch April 20, 2017 21:11
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

LGTM

@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 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.

3 participants