Skip to content

Commit cc23014

Browse files
authored
Merge pull request #1062 from turkeylurkey/issue-1060
Add environment variable to set the timeout when starting dev mode Liberty for debugging
2 parents dbfdc11 + 1cf2def commit cc23014

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/main/java/io/openliberty/tools/intellij/util/DebugModeHandler.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2022 IBM Corporation.
2+
* Copyright (c) 2022, 2024 IBM Corporation.
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
@@ -165,15 +165,16 @@ private void createAndRunDebugConfiguration(ProgressIndicator indicator, Liberty
165165
*/
166166
private String waitForSocketActivation(ProgressIndicator monitor, LibertyModule libertyModule, String host, int debugPort) throws Exception {
167167
byte[] handshakeString = "JDWP-Handshake".getBytes(StandardCharsets.US_ASCII);
168-
int retryLimit = 60; // wait up to 3 minutes for dev mode to start (polling rate 20 per minute, 3s)
168+
int retryLimit = getDebuggerTimeoutInSeconds();
169+
int retryInc = 3; // time to wait after each try
169170

170171
// Retrieve the location of the server.env in the liberty installation at the default location (wpl/usr/servers/<serverName>).
171172
Path serverEnvPath = getServerEnvPath(libertyModule);
172173
// If the server.env has not been created yet then someone did a 'clean' before starting
173174
boolean cleanStart = serverEnvPath == null;
174175
Path serverEnvBakPath = null;
175176

176-
for (int retryCount = 0; retryCount < retryLimit; retryCount++) {
177+
for (int retryCount = 0; retryCount < retryLimit; retryCount+=retryInc) {
177178
// check if cancelled
178179
if (monitor.isCanceled()) {
179180
return null;
@@ -210,11 +211,30 @@ private String waitForSocketActivation(ProgressIndicator monitor, LibertyModule
210211
LOGGER.trace(String.format("ConnectException waiting for runtime to start on port %d", debugPort));
211212
}
212213
}
213-
TimeUnit.SECONDS.sleep(3);
214+
TimeUnit.SECONDS.sleep(retryInc);
214215
}
215216
throw new Exception(LocalizedResourceUtil.getMessage("cannot.attach.debugger.host.port", host, String.format("%d",debugPort)));
216217
}
217218

219+
/**
220+
* Check an environment variable to see if the user specifies a timeout to use for the debugger.
221+
* This is not an exposed environment variable, it is only used for testing.
222+
*/
223+
private int getDebuggerTimeoutInSeconds() {
224+
// Number of seconds to wait for Liberty dev mode to start. Note that Gradle can take a while
225+
// to get going so we default to 3 minutes. During testing it can take even longer, 4-5 minutes.
226+
int defaultTimeout = 180;
227+
String userSpecifiedTimeout = System.getenv("LIBERTY_TOOLS_INTELLIJ_DEBUGGER_TIMEOUT");
228+
if (userSpecifiedTimeout != null) {
229+
try {
230+
return Integer.parseInt(userSpecifiedTimeout);
231+
} catch (NumberFormatException n) {
232+
// return the default below
233+
}
234+
}
235+
return defaultTimeout;
236+
}
237+
218238
/**
219239
* Returns the default path of the server.env file after Liberty server deployment.
220240
*

src/test/resources/ci/scripts/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ main() {
155155

156156
# Start the IDE.
157157
echo -e "\n$(${currentTime[@]}): INFO: Starting the IntelliJ IDE..."
158+
# Have liberty tools debugger wait 480s for Maven or Gradle dev mode to start
159+
export LIBERTY_TOOLS_INTELLIJ_DEBUGGER_TIMEOUT=480
158160
./gradlew runIdeForUiTests -PuseLocal=$USE_LOCAL_PLUGIN --info > remoteServer.log 2>&1 &
159161

160162
# Wait for the IDE to come up.

0 commit comments

Comments
 (0)