-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
Conversation
Sonatype Lift is retiringSonatype 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. |
@symat @eolivelli , similar to #2040 and #1524. Call for review. Thanks. |
There was a problem hiding this 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!
There was a problem hiding this 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?
c775218
to
8a97b79
Compare
@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. |
8a97b79
to
92dfa5f
Compare
@anmolnar , please take a look when available. Thanks. |
@anmolnar , please take a look when available. Thanks. |
@showuon You have checkstyle validation error
|
@anmolnar , fixed. Please also help backport to 3.8/3.9 branch if no other comments. Thank you very much. |
1106c8e
to
894642d
Compare
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. |
There was a problem hiding this 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
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-inline</artifactId> | ||
<version>${mockito.version}</version> | ||
</dependency> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
// 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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Thanks!
… into ZOOKEEPER-4708_2
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. |
@eolivelli @symat @tisonkun @ztzg, please take a look when available. Thanks. |
@eolivelli @symat @tisonkun @ztzg, please take a look. Thanks. |
1 similar comment
@eolivelli @symat @tisonkun @ztzg, please take a look. Thanks. |
Will this be merged anytime soon? We would greatly appreciate if this was merged as our infrastructure is greatly affected by this issue |
@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. |
@clemcvlcs @showuon |
@anmolnar , conflicts resolved. Thanks. |
Merged. Thanks for the contribution @showuon ! |
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 thehostname
andport
are identical, but theIP 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.