|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2022 IBM Corporation. |
| 2 | + * Copyright (c) 2022, 2024 IBM Corporation. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made available under the |
5 | 5 | * terms of the Eclipse Public License v. 2.0 which is available at |
@@ -165,15 +165,16 @@ private void createAndRunDebugConfiguration(ProgressIndicator indicator, Liberty |
165 | 165 | */ |
166 | 166 | private String waitForSocketActivation(ProgressIndicator monitor, LibertyModule libertyModule, String host, int debugPort) throws Exception { |
167 | 167 | 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 |
169 | 170 |
|
170 | 171 | // Retrieve the location of the server.env in the liberty installation at the default location (wpl/usr/servers/<serverName>). |
171 | 172 | Path serverEnvPath = getServerEnvPath(libertyModule); |
172 | 173 | // If the server.env has not been created yet then someone did a 'clean' before starting |
173 | 174 | boolean cleanStart = serverEnvPath == null; |
174 | 175 | Path serverEnvBakPath = null; |
175 | 176 |
|
176 | | - for (int retryCount = 0; retryCount < retryLimit; retryCount++) { |
| 177 | + for (int retryCount = 0; retryCount < retryLimit; retryCount+=retryInc) { |
177 | 178 | // check if cancelled |
178 | 179 | if (monitor.isCanceled()) { |
179 | 180 | return null; |
@@ -210,11 +211,30 @@ private String waitForSocketActivation(ProgressIndicator monitor, LibertyModule |
210 | 211 | LOGGER.trace(String.format("ConnectException waiting for runtime to start on port %d", debugPort)); |
211 | 212 | } |
212 | 213 | } |
213 | | - TimeUnit.SECONDS.sleep(3); |
| 214 | + TimeUnit.SECONDS.sleep(retryInc); |
214 | 215 | } |
215 | 216 | throw new Exception(LocalizedResourceUtil.getMessage("cannot.attach.debugger.host.port", host, String.format("%d",debugPort))); |
216 | 217 | } |
217 | 218 |
|
| 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 | + |
218 | 238 | /** |
219 | 239 | * Returns the default path of the server.env file after Liberty server deployment. |
220 | 240 | * |
|
0 commit comments