From 268426fbede670bc4d6218e7173962fdfcfa0f1e Mon Sep 17 00:00:00 2001 From: Takahiro Nagao Date: Tue, 17 Dec 2024 17:19:58 +0900 Subject: [PATCH 1/2] Fix exhaustion of ephemeral ports Signed-off-by: Takahiro Nagao --- .../enterprise/admin/servermgmt/cli/StopDomainCommand.java | 3 ++- .../com/sun/enterprise/universal/process/ProcessUtils.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java index d524248a075..0b2c74bfc27 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java @@ -204,7 +204,8 @@ private void waitForDeath(File watchedPid) throws CommandException { final Duration timeout = Duration.ofMillis(DEATH_TIMEOUT_MS); final Supplier deathSign; if (isLocal()) { - deathSign = () -> !ProcessUtils.isListening(addr) && !ProcessUtils.isAlive(watchedPid); + // watch process id first to reduce the number of opened ephemeral ports + deathSign = () -> !ProcessUtils.isAlive(watchedPid) && !ProcessUtils.isListening(addr); } else { deathSign = () -> !ProcessUtils.isListening(addr); } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java index a70c18a6a49..4b1a21d9ebb 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java @@ -230,7 +230,11 @@ public static boolean waitFor(Supplier sign, Duration timeout, boolean System.out.flush(); } } - Thread.yield(); + try { + Thread.sleep(100L); + } catch (InterruptedException e) { + LOG.log(TRACE, "Interrupted while waiting", e); + } } return false; } finally { From 6aaa20e8385e9cac0ed79a1a2f51efbdab5ea07c Mon Sep 17 00:00:00 2001 From: Takahiro Nagao Date: Thu, 19 Dec 2024 12:04:13 +0900 Subject: [PATCH 2/2] Fix waitFor not to swallow InterruptedException Signed-off-by: Takahiro Nagao --- .../com/sun/enterprise/universal/process/ProcessUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java index 4b1a21d9ebb..7915dcb58a2 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java @@ -39,6 +39,7 @@ import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.INFO; import static java.lang.System.Logger.Level.TRACE; +import static java.lang.System.Logger.Level.WARNING; import static java.nio.charset.StandardCharsets.ISO_8859_1; /** @@ -233,7 +234,8 @@ public static boolean waitFor(Supplier sign, Duration timeout, boolean try { Thread.sleep(100L); } catch (InterruptedException e) { - LOG.log(TRACE, "Interrupted while waiting", e); + LOG.log(WARNING, "Interrupted while waiting", e); + break; } } return false;