8341637: java/net/Socket/UdpSocket.java fails with "java.net.BindException: Address already in use" (macos-aarch64)

Reviewed-by: jpai
This commit is contained in:
Daniel Fuchs 2024-10-14 12:29:06 +00:00
parent 1581508988
commit ba3774dc5d

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,6 +47,8 @@ import static org.testng.Assert.*;
@Test
public class UdpSocket {
private static final int MAX_RETRIES = 3;
/**
* Test using the Socket API to send/receive datagrams
*/
@ -133,16 +135,21 @@ public class UdpSocket {
}
private Socket newUdpSocket() throws IOException {
Socket s = null;
try {
s = new Socket(InetAddress.getLoopbackAddress(), 8000, false);
} catch (BindException unexpected) {
System.out.println("BindException caught retry Socket creation");
s = new Socket(InetAddress.getLoopbackAddress(), 8000, false);
private Socket newUdpSocket() throws IOException, InterruptedException {
BindException unexpected = null;
for (int i=0; i < MAX_RETRIES; i++) {
try {
return new Socket(InetAddress.getLoopbackAddress(), 8000, false);
} catch (BindException be) {
unexpected = be;
if (i != MAX_RETRIES - 1) {
System.out.printf("BindException caught: retry Socket creation [%s/%s]%n",
i + 1, MAX_RETRIES);
Thread.sleep(10 + 10 * i);
}
}
}
return s;
throw unexpected;
}
private void closeAll(Deque<Socket> sockets) throws IOException {