Skip to content

Commit 01101fb

Browse files
committed
Debug port can be still unbindable after previous JVM died
- We have issues on Windows on GHA with this. - Maybe local restarts should be done as stop-start on Windows? Respawning is not recommended and on windows it seems really risky Signed-off-by: David Matějček <[email protected]>
1 parent f103aa2 commit 01101fb

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/asadmin/Asadmin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private File getPasswordFile() {
242242
*/
243243
private AsadminResult exec(final Integer timeout, final boolean detachedAndTerse, final String... args) {
244244
final List<String> parameters = Arrays.asList(args);
245-
LOG.log(TRACE, "exec(timeout={0}, detached={1}, args={2})", timeout, detachedAndTerse, parameters);
245+
LOG.log(INFO, "exec(timeout={0}, detached={1}, args={2})", timeout, detachedAndTerse, parameters);
246246
final List<String> command = new ArrayList<>();
247247
if (asadmin.getName().endsWith(".java")) {
248248
command.add(JAVA_EXECUTABLE);

appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,6 +16,8 @@
1616

1717
package org.glassfish.main.admin.test;
1818

19+
import com.sun.enterprise.util.OS;
20+
1921
import java.io.File;
2022
import java.io.FileReader;
2123
import java.io.LineNumberReader;
@@ -69,11 +71,16 @@ public class AsadminLoggingITest {
6971

7072
private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
7173

74+
/** Fill up the server log. */
7275
@BeforeAll
73-
public static void fillUpServerLog() {
74-
// Fill up the server log.
75-
AsadminResult result = ASADMIN.exec("restart-domain", "--timeout", "60");
76-
assertThat(result, asadminOK());
76+
public static void fillUpServerLog() throws Exception {
77+
if (OS.isWindowsForSure()) {
78+
// For some reason windows can collide on debug port.
79+
assertThat(ASADMIN.exec("stop-domain"), asadminOK());
80+
assertThat(ASADMIN.exec("start-domain"), asadminOK());
81+
} else {
82+
assertThat(ASADMIN.exec("restart-domain"), asadminOK());
83+
}
7784
}
7885

7986
@Test

nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public final void launch() throws GFLauncherException {
211211
LOG.log(INFO, () -> "Debugging will be available on port " + debugPort + ".");
212212
}
213213
}
214+
logCommandLine();
214215
try {
215216
startTime = System.currentTimeMillis();
216217
if (isFakeLaunch()) {
@@ -284,7 +285,6 @@ public void setup() throws GFLauncherException, MiniXmlParserException {
284285
setClasspath();
285286
initCommandLine();
286287
setJvmOptions();
287-
logCommandLine();
288288

289289
// if no <network-config> element, we need to upgrade this domain
290290
needsAutoUpgrade = !domainXML.hasNetworkConfig();

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ protected final String waitForStart(final Long oldPid, final ServerLifeSignCheck
404404
if (startTimeout != null && startTimeout.isNegative()) {
405405
throw new CommandException(reportPidFileIssue(pidFile));
406406
}
407-
final Long pid = loadPid(getServerDirs().getPidFile());
407+
final Long pid = pidFile.isFile() ? loadPid(pidFile) : null;
408408
if (pid == null) {
409409
throw new CommandException(reportPidFileIssue(pidFile));
410410
}

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartServerHelper.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,10 @@ public static List<HostAndPort> parseCustomEndpoints(String customEndpoints) thr
277277
* So we have to wait a bit.
278278
*/
279279
private static void checkFreeDebugPort(Integer debugPort, Duration timeout, boolean terse) {
280-
if (debugPort == null) {
280+
if (debugPort == null || NetUtils.isPortFree(debugPort)) {
281281
return;
282282
}
283-
final HostAndPort debugEndpoint = new HostAndPort("localhost", debugPort, false);
284-
if (!ProcessUtils.isListening(debugEndpoint)) {
285-
return;
286-
}
287-
ProcessUtils.waitWhileListening(debugEndpoint, timeout, !terse);
283+
ProcessUtils.waitFor(() -> NetUtils.isPortFree(debugPort), Duration.ofSeconds(10L), terse);
288284
}
289285

290286
private static void checkFreeAdminPorts(List<HostAndPort> endpoints) throws GFLauncherException {

0 commit comments

Comments
 (0)