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

Don't cache Bookie hostname DNS resolution forever #1762

Merged
merged 2 commits into from Oct 28, 2018

Conversation

merlimat
Copy link
Contributor

Motivation

BookieSocketAddress is resolving the bookie DNS name in its constructor and then using the already resolved InetSocketAddress instance.

If the IP of a bookie changes, the BK client will continue to use the old IP address.

Changes

Construct a new InetSocketAddress each time getSocketAddress() gets called (eg: each time we attempt to make a new connection) so that we're making sure to get the right IP.

I cannot think of a good way to add unit test for this at this point, suggestions are welcome.

I think this should be included in a patch release as well 4.7.3 or 4.8.1

@merlimat merlimat added this to the 4.9.0 milestone Oct 26, 2018
@merlimat merlimat self-assigned this Oct 26, 2018
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Okay.

+1 for not adding tests, it will very tricky

But we should add a comment, in the future people could think it will be a good idea to cache the value and undo this patch

@merlimat
Copy link
Contributor Author

But we should add a comment, in the future people could think it will be a good idea to cache the value and undo this patch

Good point, I'll add comment. In future we should try to move to use async DNS from Netty instead of relying on the blocking DNS resolution from JDK + OS. We've been using that in Pulsar for 1 year now and it has been working very well.

Copy link
Contributor

@ivankelly ivankelly left a comment

Choose a reason for hiding this comment

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

I think unit testing would be hard. Should be possible with an integration test, but I'm not sure if it's worth it.

@merlimat
Copy link
Contributor Author

@eolivelli Added comment

@dlg99
Copy link
Contributor

dlg99 commented Oct 26, 2018

LGTM but you also need to consider effects of
-Dnetworkaddress.cache.ttl jvm option.

networkaddress.cache.ttl
Specified in java.security to indicate the caching policy for successful name lookups from the name service.. 
The value is specified as integer to indicate the number of seconds to cache the successful lookup.

A value of -1 indicates "cache forever". 

The default behavior is to cache forever when a security manager is installed, 
and to cache for an implementation specific period of time, when a security manager is not installed.

@merlimat
Copy link
Contributor Author

@dlg99 -Dnetworkaddress.cache.ttl cannot be passed as system property from CLI but rather included in java.security property file.

In any case, the current behavior is caching the DNS resolution forever in the BK client process. That comes before reaching the JVM DNS cache or the OS DNS cache. By creating new instances of InetSocketAddress we will rely on the JVM cache, that depends on the networkaddress.cache.ttl setting.

(BTW: I think the JVM cache is a bad thing on its own, but that's a different story... :) )

@merlimat
Copy link
Contributor Author

run integration tests

@sijie
Copy link
Member

sijie commented Oct 27, 2018

IGNORE IT CI

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

+1
Looks good. Thanks

@sijie sijie merged commit 3d8bad4 into apache:master Oct 28, 2018
sijie pushed a commit that referenced this pull request Oct 28, 2018
### Motivation

`BookieSocketAddress` is resolving the bookie DNS name in its constructor and then using the already resolved `InetSocketAddress` instance.

If the IP of a bookie changes, the BK client will continue to use the old IP address.

### Changes

Construct a new `InetSocketAddress` each time `getSocketAddress()` gets called (eg: each time we attempt to make a new connection) so that we're making sure to get the right IP.

I cannot think of a good way to add unit test for this at this point, suggestions are welcome.

I think this should be included in a patch release as well 4.7.3 or 4.8.1

Reviewers: Andrey Yegorov <None>, Enrico Olivelli <eolivelli@gmail.com>, Sijie Guo <sijie@apache.org>, Ivan Kelly <ivank@apache.org>

This closes #1762 from merlimat/fix-dns

(cherry picked from commit 3d8bad4)
Signed-off-by: Sijie Guo <sijie@apache.org>
sijie pushed a commit that referenced this pull request Oct 28, 2018
### Motivation

`BookieSocketAddress` is resolving the bookie DNS name in its constructor and then using the already resolved `InetSocketAddress` instance.

If the IP of a bookie changes, the BK client will continue to use the old IP address.

### Changes

Construct a new `InetSocketAddress` each time `getSocketAddress()` gets called (eg: each time we attempt to make a new connection) so that we're making sure to get the right IP.

I cannot think of a good way to add unit test for this at this point, suggestions are welcome. 

I think this should be included in a patch release as well 4.7.3 or 4.8.1

Reviewers: Andrey Yegorov <None>, Enrico Olivelli <eolivelli@gmail.com>, Sijie Guo <sijie@apache.org>, Ivan Kelly <ivank@apache.org>

This closes #1762 from merlimat/fix-dns
@sijie
Copy link
Member

sijie commented Oct 28, 2018

merged to master, branch-4.8 and branch-4.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants