Skip to content

Commit ad2a55e

Browse files
The destroying of processes which aren't needed
1 parent 4c44746 commit ad2a55e

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,19 @@ private static String getProcessOutput(InputStream stream ) throws IOException {
8484
private static void validateNodeJSVersion(){
8585
Runtime rt = Runtime.getRuntime();
8686
String result = null;
87+
Process p = null;
8788
try {
88-
Process p = rt.exec(NODE_COMMAND_PREFIX + " node -v");
89+
p = rt.exec(NODE_COMMAND_PREFIX + " node -v");
8990
p.waitFor();
9091
result = getProcessOutput(p.getInputStream());
9192
} catch (Exception e) {
9293
throw new InvalidNodeJSInstance("Node.js is not installed", e);
9394
}
95+
finally {
96+
if (p != null)
97+
p.destroy();
98+
}
99+
94100
String versionNum = result.replace("v","");
95101
String[] tokens = versionNum.split("\\.");
96102
if (Integer.parseInt(tokens[0]) < REQUIRED_MAJOR_NODE_JS ||
@@ -102,13 +108,18 @@ private static void validateNodeJSVersion(){
102108
private static File findNodeInCurrentFileSystem(){
103109
Runtime rt = Runtime.getRuntime();
104110
String instancePath;
111+
Process p = null;
105112
try {
106-
Process p = rt.exec(returnCommandThatSearchesForDefaultNode());
113+
p = rt.exec(returnCommandThatSearchesForDefaultNode());
107114
p.waitFor();
108115
instancePath = getProcessOutput(p.getInputStream());
109116
} catch (Exception e) {
110117
throw new RuntimeException(e);
111118
}
119+
finally {
120+
if (p != null)
121+
p.destroy();
122+
}
112123

113124
File result;
114125
if (StringUtils.isBlank(instancePath) || !(result = new File(instancePath + File.separator + NODE_MODULES_FOLDER +
@@ -154,17 +165,21 @@ protected File findDefaultExecutable() {
154165
} catch (IOException e) {
155166
throw new RuntimeException(e);
156167
}
157-
OutputStream outputStream = p.getOutputStream();
158-
PrintStream out = new PrintStream(outputStream) ;
159-
out.println("console.log(process.execPath);") ;
160-
out.close();
161168

162169
try {
170+
OutputStream outputStream = p.getOutputStream();
171+
PrintStream out = new PrintStream(outputStream) ;
172+
out.println("console.log(process.execPath);") ;
173+
out.close();
174+
163175
return new File(getProcessOutput(p.getInputStream()));
164176
}
165177
catch (Throwable t){
166178
throw new RuntimeException(t);
167179
}
180+
finally {
181+
p.destroy();
182+
}
168183
}
169184

170185
/**

0 commit comments

Comments
 (0)