Skip to content

Commit 39734cc

Browse files
original-brownbearkcm
authored andcommitted
TEST: Stablize Minio Free Port Search (#34894)
* Binding to `0` gives us free ports that are assigned sequentially by Linux making collisions much less likely compared to manually finding a free port in a range * Closes #32208
1 parent 1e6a26a commit 39734cc

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

plugins/repository-s3/build.gradle

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,11 @@ if (useFixture && minioDistribution) {
202202

203203
doLast {
204204
// get free port
205-
for (int port = 60920; port < 60940; port++) {
206-
try {
207-
javax.net.ServerSocketFactory.getDefault().createServerSocket(port, 1, InetAddress.getByName(minioAddress)).close()
208-
minioPort = port
209-
break
210-
} catch (BindException e) {
211-
logger.info("Port " + port + " for Minio process is already taken", e)
212-
}
205+
ServerSocket serverSocket = new ServerSocket(0, 1, InetAddress.getByName(minioAddress))
206+
try {
207+
minioPort = serverSocket.localPort
208+
} finally {
209+
serverSocket.close()
213210
}
214211
if (minioPort == 0) {
215212
throw new GradleException("Could not find a free port for Minio")

0 commit comments

Comments
 (0)