Skip to content

Commit

Permalink
Avoid using wildcard address on macOS if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuch committed Jun 27, 2024
1 parent fb40557 commit 4b3f5f1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/jdk/java/nio/channels/DatagramChannel/AdaptorBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.*;
import java.lang.reflect.Field;

import jdk.test.lib.Platform;


public class AdaptorBasic {

Expand Down Expand Up @@ -118,7 +120,13 @@ static void test(InetSocketAddress dst,
while (true) {
DatagramChannel dc = DatagramChannel.open();
ds = dc.socket();
ds.bind(new InetSocketAddress(0));
if (Platform.isOSX() && dst.getAddress().isLoopbackAddress()) {
// avoid binding to the wildcard on macOS if possible, in order to limit
// potential port conflict issues
ds.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
} else {
ds.bind(new InetSocketAddress(0));
}
// on some systems it may be possible to bind two sockets
// to the same port if one of them is bound to the wildcard,
// if that happens, try again...
Expand Down

0 comments on commit 4b3f5f1

Please sign in to comment.