From 3f2d1528dccb5cd5939599ba200e6eed75ff603f Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 21 Dec 2020 09:26:40 +0100 Subject: [PATCH] [wsl] timeout for WSL probing commands GitOrigin-RevId: 8a27aef217dc40e2791b9321ad81bc3d0f64ef38 --- .../execution/wsl/WSLCommandLineOptions.java | 16 +++++++++++++++- .../execution/wsl/WslDistributionDescriptor.java | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/execution/wsl/WSLCommandLineOptions.java b/platform/platform-impl/src/com/intellij/execution/wsl/WSLCommandLineOptions.java index 9755deca0c9f..46012fdf3104 100644 --- a/platform/platform-impl/src/com/intellij/execution/wsl/WSLCommandLineOptions.java +++ b/platform/platform-impl/src/com/intellij/execution/wsl/WSLCommandLineOptions.java @@ -15,6 +15,7 @@ public final class WSLCommandLineOptions { private String myRemoteWorkingDirectory; private boolean myPassEnvVarsUsingInterop = false; private final List myInitShellCommands = new ArrayList<>(); + private int myTimeout = -1; public boolean isLaunchWithWslExe() { return myLaunchWithWslExe && Experiments.getInstance().isFeatureEnabled("wsl.execute.with.wsl.exe"); @@ -98,6 +99,18 @@ public final class WSLCommandLineOptions { return this; } + /** + * Specifies a timeout for WSL command execution, in milliseconds. Default value is -1 (meaning no timeout). + */ + public int getTimeout() { + return myTimeout; + } + + public WSLCommandLineOptions withTimeout(int timeout) { + myTimeout = timeout; + return this; + } + @Override public String toString() { return "launchWithWslExe=" + myLaunchWithWslExe + @@ -105,6 +118,7 @@ public final class WSLCommandLineOptions { ", sudo=" + mySudo + ", remoteWorkingDirectory='" + myRemoteWorkingDirectory + '\'' + ", passEnvVarsUsingInterop=" + myPassEnvVarsUsingInterop + - ", initCommands=" + myInitShellCommands; + ", initCommands=" + myInitShellCommands + + ", timeout=" + myTimeout; } } diff --git a/platform/platform-impl/src/com/intellij/execution/wsl/WslDistributionDescriptor.java b/platform/platform-impl/src/com/intellij/execution/wsl/WslDistributionDescriptor.java index 63744dcd103b..b2d5cdaf9ebb 100644 --- a/platform/platform-impl/src/com/intellij/execution/wsl/WslDistributionDescriptor.java +++ b/platform/platform-impl/src/com/intellij/execution/wsl/WslDistributionDescriptor.java @@ -131,7 +131,7 @@ final class WslDistributionDescriptor { return WSLDistribution.DEFAULT_WSL_MNT_ROOT; } - WSLCommandLineOptions options = new WSLCommandLineOptions().setLaunchWithWslExe(true).setExecuteCommandInShell(false); + WSLCommandLineOptions options = new WSLCommandLineOptions().setLaunchWithWslExe(true).setExecuteCommandInShell(false).withTimeout(60_000); String wslCurrentDirectory = readWslOutputLine(options, Collections.singletonList("pwd")); if (wslCurrentDirectory == null) return WSLDistribution.DEFAULT_WSL_MNT_ROOT; @@ -166,7 +166,7 @@ final class WslDistributionDescriptor { ProcessOutput output; try { - output = distribution.executeOnWsl(command, options, -1, null); + output = distribution.executeOnWsl(command, options, options.getTimeout(), null); } catch (ExecutionException e) { LOG.warn("Start failed on " + getId(), e); @@ -191,6 +191,6 @@ final class WslDistributionDescriptor { @NonNls @Nullable String getEnvironmentVariable(String name) { - return readWslOutputLine(new WSLCommandLineOptions(), Arrays.asList("printenv", name)); + return readWslOutputLine(new WSLCommandLineOptions().withTimeout(60_000), Arrays.asList("printenv", name)); } }