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

ZOOKEEPER-4708: recreateSocketAddresses before comparing addresses #2041

Merged
merged 12 commits into from
Sep 12, 2024

Conversation

showuon
Copy link
Contributor

@showuon showuon commented Jul 31, 2023

Found 2 places we will compare the addresses to check if there's any major change, but the addresses comparison will compare hostname + IP address + port. If the DNS is slow, there might be chances that the hostname and port are identical, but the IP address has <unresolved> V.S. x.x.x.x. So the result will be the unexpected unequal.

This PR tried to recreateSocketAddresses before comparing the addresses to fix the issue.

Note: No tests added because it didn't change any logic. Just need to make sure it passes the existing tests.

@sonatype-lift
Copy link

sonatype-lift bot commented Jul 31, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@showuon
Copy link
Contributor Author

showuon commented Jul 31, 2023

@symat @eolivelli , similar to #2040 and #1524. Call for review. Thanks.

Copy link

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

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

Thanks @showuon! I tried it on different environments running Kubernetes (i.e. minikube, AKS, OpenShift, ...) and it worked fine for me!

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Thanks @showuon , lgtm.
Have you considered adding a unit test for this?

@showuon
Copy link
Contributor Author

showuon commented Aug 13, 2023

@anmolnar , thanks for the comment. Tests added.

Note: It's not easy to test the slow DNS scenario, so I tried to verify the method is invoked as expected, alternatively.

Thanks.

@showuon
Copy link
Contributor Author

showuon commented Aug 28, 2023

@anmolnar , please take a look when available. Thanks.

@showuon
Copy link
Contributor Author

showuon commented Oct 3, 2023

@anmolnar , please take a look when available. Thanks.

@anmolnar
Copy link
Contributor

@showuon You have checkstyle validation error

Error:  /home/runner/work/zookeeper/zookeeper/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java:43:1: Extra separation in import group before 'org.apache.jute.OutputArchive' [ImportOrder]

@showuon
Copy link
Contributor Author

showuon commented Oct 18, 2023

@showuon You have checkstyle validation error

Error:  /home/runner/work/zookeeper/zookeeper/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java:43:1: Extra separation in import group before 'org.apache.jute.OutputArchive' [ImportOrder]

@anmolnar , fixed. Please also help backport to 3.8/3.9 branch if no other comments. Thank you very much.

@showuon
Copy link
Contributor Author

showuon commented Oct 19, 2023

The compatibility test failed on java 11 in 3.6.3, but passed on java 8 in 3.6.3. I think it should be fine. Thanks.

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

nit: In unit tests you don't validate that recreateSocketAddress's return object is not the same as the input. Otherwise lgtm.
Let's wait for another committer @eolivelli @symat @tisonkun @ztzg

pom.xml Outdated
Comment on lines 706 to 710
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
</dependency>
Copy link
Contributor Author

@showuon showuon Oct 20, 2023

Choose a reason for hiding this comment

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

Adding mockito-inline module to support final method mocking (in InetAddress class). See here.

Copy link
Contributor

@anmolnar anmolnar Oct 20, 2023

Choose a reason for hiding this comment

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

I think that's fine, but I think you should add test scope to it.

<scope>test</scope>

Comment on lines +271 to +289
// test case 3: Simulating the DNS returning different IP address for the same hostname during recreation.
// After recreateSocketAddresses, the MultipleAddresses should contain the updated IP address instance while other fields unchanged.
InetAddress spyInetAddr = Mockito.spy(loopback);
InetSocketAddress addr3 = new InetSocketAddress(spyInetAddr, PortAssignment.unique());
// Verify the address is the old IP before recreateSocketAddresses.
assertEquals(oldIP, addr3.getAddress().getHostAddress());
multipleAddresses = new MultipleAddresses(Arrays.asList(addr3));
// simulating the DNS returning different IP address
when(spyInetAddr.getHostAddress()).thenReturn(newIP);

// Verify after recreateSocketAddresses, the multipleAddresses should have different IP address result
MultipleAddresses newMultipleAddress = leader.recreateSocketAddresses(multipleAddresses);
assertNotEquals(multipleAddresses, newMultipleAddress);
assertEquals(1, multipleAddresses.getAllAddresses().size());
InetSocketAddress newAddr = multipleAddresses.getAllAddresses().iterator().next();
// Verify the hostName should still be the same
assertEquals(loopback.getHostName(), newAddr.getAddress().getHostName());
// Verify the IP address has changed.
assertEquals(newIP, newAddr.getAddress().getHostAddress());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anmolnar , added a test case to verify recreateSocketAddress return object is not the same as the input. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm. Thanks!

@see-quick
Copy link

We have encountered an issue affecting over 50% of the test cases within our testing infrastructure. We would greatly appreciate it if we could move forward with addressing this issue.

^^ @eolivelli, @symat, @tisonkun, and @ztzg

I appreciate your attention to this matter in advance.

@showuon
Copy link
Contributor Author

showuon commented Dec 5, 2023

@eolivelli @symat @tisonkun @ztzg, please take a look when available. Thanks.

@showuon
Copy link
Contributor Author

showuon commented Dec 13, 2023

@eolivelli @symat @tisonkun @ztzg, please take a look. Thanks.

1 similar comment
@showuon
Copy link
Contributor Author

showuon commented Jan 11, 2024

@eolivelli @symat @tisonkun @ztzg, please take a look. Thanks.

@karthick-ponnusamy
Copy link

karthick-ponnusamy commented Apr 10, 2024

Will this be merged anytime soon? We would greatly appreciate if this was merged as our infrastructure is greatly affected by this issue

@clemcvlcs
Copy link

@eolivelli @symat @tisonkun @ztzg

This PR is approved since one year now. Any chance you can have a look at this ?

We are also affected by this issue, probably as many other people.

@anmolnar
Copy link
Contributor

@clemcvlcs @showuon
Sure, I'm happy to merge it. Please rebase and resolve conflicts.

@showuon
Copy link
Contributor Author

showuon commented Sep 12, 2024

@anmolnar , conflicts resolved. Thanks.

@anmolnar anmolnar merged commit 34c6d9f into apache:master Sep 12, 2024
14 checks passed
@anmolnar
Copy link
Contributor

Merged. Thanks for the contribution @showuon !
I cannot backport to branch-3.9 , because it has conflicts. Please open new PR if you'd like to backport.

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.

6 participants