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

Tries all hosts resolved for DNS name #2722

Merged
merged 12 commits into from Jan 18, 2022

Conversation

adiamzn
Copy link
Contributor

@adiamzn adiamzn commented Dec 8, 2021

Problem

By default the default DNS resolver in InetAddress class may cache ip addresses after successfully connecting for the first time.

This is can be problematic if we expect to be able to connect to more than one IP address behind a DNS name.
For example multiple read replicas behind a common dns name, or a failed host that was replaced and now has a new ip.

Proposed Fixed

When creating connecting to a host using a dns name, try all addresses the DNS server was able to resolve.

Copy link
Collaborator

@yangbodong22011 yangbodong22011 left a comment

Choose a reason for hiding this comment

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

Thanks for you contribution.

This brings almost no performance loss, because java.net.InetAddress#getByName(java.lang.String) also calls java.net.InetAddress#getAllByName(java.lang.String), but gets [0 ] Element, just add the overhead of Collections.shuffle(hosts), but it can be ignored.

     public static InetAddress getByName(String host)
         throws UnknownHostException {
         return InetAddress.getAllByName(host)[0];
     }

Some comments are detailed in the code section.

@sazzad16 sazzad16 added this to the 4.1.0 milestone Dec 12, 2021
zeekling
zeekling previously approved these changes Dec 13, 2021
@adiamzn adiamzn force-pushed the bugfix-resolve-all-hosts branch 2 times, most recently from 94dd5cd to 93bfc3b Compare December 13, 2021 14:39
@adiamzn
Copy link
Contributor Author

adiamzn commented Dec 18, 2021

@sazzad16 are there any further changes required?

@sazzad16
Copy link
Collaborator

are there any further changes required?

@adiamzn No. We're good for now. Thanks!

We'll ping you in case anything comes up. Have a nice day!

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2021

Codecov Report

Merging #2722 (7d2d30b) into master (9b702b8) will increase coverage by 0.01%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2722      +/-   ##
============================================
+ Coverage     58.41%   58.42%   +0.01%     
- Complexity     3068     3070       +2     
============================================
  Files           177      177              
  Lines         11011    11024      +13     
  Branches        629      632       +3     
============================================
+ Hits           6432     6441       +9     
- Misses         4361     4364       +3     
- Partials        218      219       +1     
Impacted Files Coverage Δ
...redis/clients/jedis/DefaultJedisSocketFactory.java 93.42% <87.50%> (-1.82%) ⬇️
...in/java/redis/clients/jedis/ConnectionFactory.java 63.26% <0.00%> (-4.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b702b8...7d2d30b. Read the comment docs.

dengliming
dengliming previously approved these changes Jan 18, 2022
sazzad16
sazzad16 previously approved these changes Jan 18, 2022
@sazzad16 sazzad16 dismissed stale reviews from dengliming and themself via 5ba4b7b January 18, 2022 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants