TanYuxin-tyx commented on PR #22471:
URL: https://github.com/apache/flink/pull/22471#issuecomment-1519868580
@zentol Thanks for joining the review.
`InetSocketAddress` only uses a random port when the **`bind`** operation
occurs, as seen in the InetSocketAddress docs.
But in this test, it does not trigger the `bind` operation obviously, so it
uses port 0 directly and causes the test to be unstable when port 0 is
occupied. I tested locally and the test often fails because of the
`BindException`.
If you do not agree on the fix, maybe another fixing method is that use the
`bind` to trigger to choose an available port like this to replace the line
`InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(),
0)`.
```
ServerSocket serverSocket = new ServerSocket();
InetSocketAddress address = new
InetSocketAddress(InetAddress.getLocalHost(), 0);
System.out.println("The port 1 " + address.getPort());
serverSocket.bind(address);
serverSocket.close();
System.out.println("The port 2 " + serverSocket.getLocalPort());
InetSocketAddress serverAddress =
new InetSocketAddress(InetAddress.getLocalHost(),
serverSocket.getLocalPort());
```
(These `System.out.println` should be removed. They are only used to see the
results.)
You can see that `port 1` is 0 and `port 2` is another available port. Then
the test will be stable.
WDYT about the new fixing method?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]