You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/06/21 02:25:04 UTC

[GitHub] [pulsar] hangc0276 opened a new pull request, #16152: [fix][client]Fix auto cluster failover can't resolve host bug

hangc0276 opened a new pull request, #16152:
URL: https://github.com/apache/pulsar/pull/16152

   ### Motivation
   When running a Pulsar client with auto cluster failover, it will throw the following exception when detecting the pulsar service URL.
   ```
   2022-06-21T09:59:52,646+0800 WARN  [main] o.a.p.c.i.AutoClusterFailoverTest@328 - Failed to probe available, url: pulsar://localhost:11195 
   java.net.UnknownHostException: localhost
   	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[?:1.8.0_131]
   	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_131]
   	at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_131]
   	at org.apache.pulsar.client.impl.AutoClusterFailoverTest.testUrl(AutoClusterFailoverTest.java:324) ~[test-classes/:?]
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
   	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
   	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) ~[testng-7.3.0.jar:?]
   	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) ~[testng-7.3.0.jar:?]
   	at java.util.ArrayList.forEach(ArrayList.java:1249) [?:1.8.0_131]
   	at org.testng.TestRunner.privateRun(TestRunner.java:764) [testng-7.3.0.jar:?]
   	at org.testng.TestRunner.run(TestRunner.java:585) [testng-7.3.0.jar:?]
   	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384) [testng-7.3.0.jar:?]
   	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378) [testng-7.3.0.jar:?]
   	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337) [testng-7.3.0.jar:?]
   	at org.testng.SuiteRunner.run(SuiteRunner.java:286) [testng-7.3.0.jar:?]
   	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) [testng-7.3.0.jar:?]
   	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) [testng-7.3.0.jar:?]
   	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218) [testng-7.3.0.jar:?]
   	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) [testng-7.3.0.jar:?]
   	at org.testng.TestNG.runSuites(TestNG.java:1069) [testng-7.3.0.jar:?]
   	at org.testng.TestNG.run(TestNG.java:1037) [testng-7.3.0.jar:?]
   	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66) [testng-rt.jar:?]
   	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109) [testng-rt.jar:?]
   ```
   
   It was introduced by https://github.com/apache/pulsar/pull/14454. 
   
   The root cause is that the `resolver.resolveHost()` will return the InetSocketAddress which doesn't resolve the IP address.
   https://github.com/apache/pulsar/blob/603a5cdd8e4f82a27c1341c93eb6162862d1e970/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java#L94
   It can't be applied to the HTTP endpoint the detect the IP: Port active.
   
   ### Modification
   Use `InetSocketAddress` object instead of `resolver.resolveHost()`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#issuecomment-1161124591

   @hangc0276 Please provide a correct documentation label for your PR.
   Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#issuecomment-1161126607

   @hangc0276 Please provide a correct documentation label for your PR.
   Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] poorbarcode commented on a diff in pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
poorbarcode commented on code in PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#discussion_r903196713


##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/AutoClusterFailoverTest.java:
##########
@@ -283,4 +291,46 @@ public void testAutoClusterFailoverSwitchTlsTrustStore() throws IOException {
                 .updateTlsTrustStorePathAndPassword(primaryTlsTrustStorePath, primaryTlsTrustStorePassword);
 
     }
+
+    @Test
+    public void testUrl() throws Exception {
+        Random random = new Random(42);
+        String serviceUrl = "pulsar://localhost:" + random.nextInt(65535);
+
+
+        PulsarServiceNameResolver resolver = new PulsarServiceNameResolver();
+
+        try {
+            resolver.updateServiceUrl(serviceUrl);
+            InetSocketAddress inetSocketAddress = new InetSocketAddress(resolver.resolveHost().getHostName(), resolver.resolveHost().getPort());
+            Socket socket = new Socket();
+            socket.connect(inetSocketAddress, 30);
+            socket.close();
+            fail();

Review Comment:
   > Seems this could be flaky? If the random port is open by coincidence.
   
   +1



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#issuecomment-1192108634

   The pr had no activity for 30 days, mark with Stale label.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#discussion_r902218791


##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/AutoClusterFailoverTest.java:
##########
@@ -283,4 +291,46 @@ public void testAutoClusterFailoverSwitchTlsTrustStore() throws IOException {
                 .updateTlsTrustStorePathAndPassword(primaryTlsTrustStorePath, primaryTlsTrustStorePassword);
 
     }
+
+    @Test
+    public void testUrl() throws Exception {
+        Random random = new Random(42);
+        String serviceUrl = "pulsar://localhost:" + random.nextInt(65535);
+
+
+        PulsarServiceNameResolver resolver = new PulsarServiceNameResolver();
+
+        try {
+            resolver.updateServiceUrl(serviceUrl);
+            InetSocketAddress inetSocketAddress = new InetSocketAddress(resolver.resolveHost().getHostName(), resolver.resolveHost().getPort());
+            Socket socket = new Socket();
+            socket.connect(inetSocketAddress, 30);
+            socket.close();
+            fail();

Review Comment:
   it is better to use a ephemeral port
   btw I am not convinced if it is worth to add such test.
   
   I believe that we can drop the test at all



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- merged pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
Technoboy- merged PR #16152:
URL: https://github.com/apache/pulsar/pull/16152


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on code in PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#discussion_r929493246


##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/AutoClusterFailoverTest.java:
##########
@@ -22,11 +22,18 @@
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 import java.io.IOException;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.Socket;

Review Comment:
   Unused import?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Jason918 commented on a diff in pull request #16152: [fix][client]Fix auto cluster failover can't resolve host bug

Posted by GitBox <gi...@apache.org>.
Jason918 commented on code in PR #16152:
URL: https://github.com/apache/pulsar/pull/16152#discussion_r902130295


##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/AutoClusterFailoverTest.java:
##########
@@ -283,4 +291,46 @@ public void testAutoClusterFailoverSwitchTlsTrustStore() throws IOException {
                 .updateTlsTrustStorePathAndPassword(primaryTlsTrustStorePath, primaryTlsTrustStorePassword);
 
     }
+
+    @Test
+    public void testUrl() throws Exception {
+        Random random = new Random(42);
+        String serviceUrl = "pulsar://localhost:" + random.nextInt(65535);
+
+
+        PulsarServiceNameResolver resolver = new PulsarServiceNameResolver();
+
+        try {
+            resolver.updateServiceUrl(serviceUrl);
+            InetSocketAddress inetSocketAddress = new InetSocketAddress(resolver.resolveHost().getHostName(), resolver.resolveHost().getPort());
+            Socket socket = new Socket();
+            socket.connect(inetSocketAddress, 30);
+            socket.close();
+            fail();

Review Comment:
   Seems this could be flaky? If the random port is open by coincidence.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org