You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/08/17 08:50:21 UTC

[GitHub] [flink] zentol commented on a change in pull request #13163: [FLINK-16789][runtime] Support JMX RMI random port assign

zentol commented on a change in pull request #13163:
URL: https://github.com/apache/flink/pull/13163#discussion_r471330016



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/management/JMXService.java
##########
@@ -85,6 +86,9 @@ private static JMXServer startJMXServerWithPortRanges(Iterator<Integer> ports) {
 		while (ports.hasNext() && successfullyStartedServer == null) {
 			JMXServer server = new JMXServer();
 			int port = ports.next();
+			if (port == 0) { // try poke with a random port when port is set to zero
+				port = tryPokeForNewPort();

Review comment:
       use `NetUtils#getAvailablePort` instead; note that this approach is inherently unreliable.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/management/JMXService.java
##########
@@ -85,6 +86,9 @@ private static JMXServer startJMXServerWithPortRanges(Iterator<Integer> ports) {
 		while (ports.hasNext() && successfullyStartedServer == null) {
 			JMXServer server = new JMXServer();
 			int port = ports.next();
+			if (port == 0) { // try poke with a random port when port is set to zero

Review comment:
       How about we map 0 to a port-range (like 10000-65000) in `JMXService#startInstance`, and process it as usual? May not be as quick, but it should work more reliably.
   
   As is we have to add in retries such that, if the port we deemed free was just taken, we try another port.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/management/JMXService.java
##########
@@ -100,4 +104,28 @@ private static JMXServer startJMXServerWithPortRanges(Iterator<Integer> ports) {
 		}
 		return successfullyStartedServer;
 	}
+
+	/**
+	 * This method tries to poke for a new port number, then releases it.
+	 *
+	 * @return a successful poked port number.
+	 */
+	private static int tryPokeForNewPort() {
+		ServerSocket serverSocket = null;
+		try {
+			serverSocket = new ServerSocket(0);
+			return serverSocket.getLocalPort();
+		} catch (IOException e) {
+			LOG.warn("Unable to allocate new Server Socket!", e);
+			return -1;

Review comment:
       If we go with this approach, we need better error handling.
   This logs a warning, returns -1, and the JMXServer will throw up another error later one.
   




----------------------------------------------------------------
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:
users@infra.apache.org