Skip to content

Commit adadf53

Browse files
Increase the timeout when attaching to integrated/external terminal (microsoft#256)
* Increase the timeout when attaching to integrated/external terminal Signed-off-by: Jinbo Wang <jinbwan@microsoft.com> * Refine the timeout error message because of long command line Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
1 parent bbf0491 commit adadf53

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchWithDebuggingDelegate.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import java.util.concurrent.CompletionException;
2121
import java.util.logging.Logger;
2222

23+
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.commons.lang3.SystemUtils;
25+
2326
import com.google.gson.JsonObject;
2427
import com.microsoft.java.debug.core.Configuration;
2528
import com.microsoft.java.debug.core.DebugException;
@@ -47,12 +50,13 @@
4750
import com.sun.jdi.connect.Connector;
4851
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
4952
import com.sun.jdi.connect.ListeningConnector;
53+
import com.sun.jdi.connect.TransportTimeoutException;
5054
import com.sun.jdi.connect.VMStartException;
5155

5256
public class LaunchWithDebuggingDelegate implements ILaunchDelegate {
5357

5458
protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
55-
private static final int ACCEPT_TIMEOUT = 10 * 1000;
59+
private static final int ATTACH_TERMINAL_TIMEOUT = 20 * 1000;
5660
private static final String TERMINAL_TITLE = "Java Debug Console";
5761
protected static final long RUNINTERMINAL_TIMEOUT = 10 * 1000;
5862

@@ -67,7 +71,7 @@ public CompletableFuture<Response> launchInTerminal(LaunchArguments launchArgume
6771
List<ListeningConnector> connectors = vmProvider.getVirtualMachineManager().listeningConnectors();
6872
ListeningConnector listenConnector = connectors.get(0);
6973
Map<String, Connector.Argument> args = listenConnector.defaultArguments();
70-
((Connector.IntegerArgument) args.get("timeout")).setValue(ACCEPT_TIMEOUT);
74+
((Connector.IntegerArgument) args.get("timeout")).setValue(ATTACH_TERMINAL_TIMEOUT);
7175
String address = listenConnector.startListening(args);
7276

7377
String[] cmds = LaunchRequestHandler.constructLaunchCommands(launchArguments, false, address);
@@ -101,6 +105,29 @@ public CompletableFuture<Response> launchInTerminal(LaunchArguments launchArgume
101105
context.setDebugSession(new DebugSession(vm));
102106
logger.info("Launching debuggee in terminal console succeeded.");
103107
resultFuture.complete(response);
108+
} catch (TransportTimeoutException e) {
109+
int commandLength = StringUtils.length(launchArguments.cwd) + 1;
110+
for (String cmd : cmds) {
111+
commandLength += StringUtils.length(cmd) + 1;
112+
}
113+
114+
final int threshold = SystemUtils.IS_OS_WINDOWS ? 8092 : 32 * 1024;
115+
String errorMessage = String.format(launchInTerminalErrorFormat, e.toString());
116+
if (commandLength >= threshold) {
117+
errorMessage = "Failed to launch debuggee in terminal. The possible reason is the command line too long. "
118+
+ "More details: " + e.toString();
119+
logger.severe(errorMessage
120+
+ "\r\n"
121+
+ "The estimated command line length is " + commandLength + ". "
122+
+ "Try to enable shortenCommandLine option in the debug launch configuration.");
123+
}
124+
125+
resultFuture.completeExceptionally(
126+
new DebugException(
127+
errorMessage,
128+
ErrorCode.LAUNCH_IN_TERMINAL_FAILURE.getId()
129+
)
130+
);
104131
} catch (IOException | IllegalConnectorArgumentsException e) {
105132
resultFuture.completeExceptionally(
106133
new DebugException(

0 commit comments

Comments
 (0)