[wsl] timeout for WSL probing commands

GitOrigin-RevId: 8a27aef217dc40e2791b9321ad81bc3d0f64ef38
This commit is contained in:
Roman Shevchenko
2020-12-21 08:26:40 +00:00
committed by intellij-monorepo-bot
parent 97f2b953ea
commit 3f2d1528dc
2 changed files with 18 additions and 4 deletions
@@ -15,6 +15,7 @@ public final class WSLCommandLineOptions {
private String myRemoteWorkingDirectory;
private boolean myPassEnvVarsUsingInterop = false;
private final List<String> 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;
}
}
@@ -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));
}
}