Skip to content
Permalink
Browse files
8240711: TestJstatdPort.java failed due to "ExportException: Port alr…
…eady in use:"

Backport-of: b70ef0d
  • Loading branch information
Olga Mikhaltsova authored and Yuri Nesterenko committed Mar 5, 2021
1 parent 71ed1cd commit 7d0aaf18c627e54466f8e1f4a9058a9bbd0cff1e
Showing 1 changed file with 10 additions and 13 deletions.
@@ -70,6 +70,8 @@ public final class JstatdTest {
private Long jstatdPid;
private boolean withExternalRegistry = false;

private volatile static boolean portInUse;

public void setServerName(String serverName) {
this.serverName = serverName;
}
@@ -84,20 +86,10 @@ public void setWithExternalRegistry(boolean withExternalRegistry) {

private Long waitOnTool(ProcessThread thread) throws Throwable {
long pid = thread.getPid();

Throwable t = thread.getUncaught();
if (t != null) {
if (t.getMessage().contains(
"java.rmi.server.ExportException: Port already in use")) {
System.out.println("Port already in use. Trying to restart with a new one...");
Thread.sleep(100);
return null;
} else {
// Something unexpected has happened
throw new Throwable(t);
}
if (portInUse) {
System.out.println("Port already in use. Trying to restart with a new one...");
return null;
}

System.out.println(thread.getName() + " pid: " + pid);
return pid;
}
@@ -274,6 +266,7 @@ private String[] getJstatdCmd() throws Exception {
}

private ProcessThread tryToSetupJstatdProcess() throws Throwable {
portInUse = false;
ProcessThread jstatdThread = new ProcessThread("Jstatd-Thread",
JstatdTest::isJstadReady, getJstatdCmd());
try {
@@ -296,6 +289,10 @@ private ProcessThread tryToSetupJstatdProcess() throws Throwable {
}

private static boolean isJstadReady(String line) {
if (line.contains("Port already in use")) {
portInUse = true;
return true;
}
return line.startsWith("jstatd started (bound to ");
}

1 comment on commit 7d0aaf1

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 7d0aaf1 Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.