kpatelatwork commented on a change in pull request #10530:
URL: https://github.com/apache/kafka/pull/10530#discussion_r617556919



##########
File path: 
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java
##########
@@ -369,9 +370,34 @@ else if (serverConnector != null && 
serverConnector.getHost() != null && serverC
         else if (serverConnector != null && serverConnector.getPort() > 0)
             builder.port(serverConnector.getPort());
 
-        log.info("Advertised URI: {}", builder.build());
+        URI uri = builder.build();
+        validateUriHost(uri);
+        log.info("Advertised URI: {}", uri);
 
-        return builder.build();
+        return uri;
+    }
+
+    /**
+     * Parses the uri and throws a more definitive error
+     * when the internal node to node communication can't happen due to an 
invalid host name.
+     */
+    static void validateUriHost(URI uri) {
+        //java URI parsing will fail silently returning null in the host if 
the host name contains invalid characters like _
+        //this bubbles up later when the Herder tries to communicate on the 
advertised url and the current HttpClient fails with an ambiguous message
+        //we need to revisit this when we upgrade to a better HttpClient that 
can communicate with such host names or throws a better error message

Review comment:
       @tombentley  excellent points about not parsing the hostname from URI 
and I also felt Utils.getHost was broken as it didn't worked on a case with 
path in the URL and that's why I passed authority to it.
   
   Let me work on a change using the approach you suggested and get back to 
you. I was doing uri.getHost null check to avoid the blast radius in case we 
didn't anticipated some pattern so I think we should still use the null check 
but as you said use the hostname that is available to us instead of parsing it 
from authority and uri.




-- 
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.

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


Reply via email to