Skip to content

Commit 054d84d

Browse files
motofixtomix26
authored andcommitted
Issue #116 Server startup fails with "port out of range:-1" error (#117)
1 parent 54fb1fd commit 054d84d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/io/zonky/test/db/postgres/embedded/EmbeddedPostgres.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ Map<String, String> getConnectConfig()
219219
private static int detectPort() throws IOException
220220
{
221221
try (ServerSocket socket = new ServerSocket(0)) {
222+
while(!socket.isBound()) {
223+
Thread.sleep(50);
224+
}
222225
return socket.getLocalPort();
226+
} catch (InterruptedException e) {
227+
Thread.currentThread().interrupt();
228+
throw new IOException("Thread interrupted", e);
223229
}
224230
}
225231

0 commit comments

Comments
 (0)