@@ -67,26 +67,33 @@ public String getVersion() {
67
67
if (cwlToolVersion != null ) {
68
68
return cwlToolVersion ;
69
69
}
70
+ Process process = null ;
70
71
try {
71
72
// Run cwltool --version
72
73
String [] command = {"cwltool" , "--version" };
73
74
ProcessBuilder cwlToolProcess = new ProcessBuilder (command );
74
- Process process = cwlToolProcess .start ();
75
+ process = cwlToolProcess .start ();
75
76
76
77
// Get input stream
77
78
InputStream is = process .getInputStream ();
78
79
InputStreamReader isr = new InputStreamReader (is );
79
80
BufferedReader br = new BufferedReader (isr );
80
81
81
82
String line ;
83
+ String cwlToolVersion ;
82
84
if ((line = br .readLine ()) != null ) {
83
85
cwlToolVersion = line .substring (line .indexOf (' ' ) + 1 );
84
- return cwlToolVersion ;
85
86
} else {
86
- return "<error getting cwl version>" ;
87
+ cwlToolVersion = "<error getting cwltool version>" ;
87
88
}
89
+ return cwlToolVersion ;
90
+
88
91
} catch (IOException ex ) {
89
- return "<error getting cwl version>" ;
92
+ return "<error getting cwltool version>" ;
93
+ } finally {
94
+ if (process != null ) {
95
+ process .destroyForcibly ();
96
+ }
90
97
}
91
98
}
92
99
@@ -100,6 +107,8 @@ public String getVersion() {
100
107
*/
101
108
private String runCwltoolOnWorkflow (String argument , String workflowUrl )
102
109
throws CWLValidationException {
110
+ Process process = null ;
111
+
103
112
try {
104
113
// Run command
105
114
String [] command = {
@@ -114,7 +123,7 @@ private String runCwltoolOnWorkflow(String argument, String workflowUrl)
114
123
workflowUrl
115
124
};
116
125
ProcessBuilder cwlToolProcess = new ProcessBuilder (command );
117
- Process process = cwlToolProcess .start ();
126
+ process = cwlToolProcess .start ();
118
127
119
128
// Read output from the process using threads
120
129
StreamGobbler inputGobbler = new StreamGobbler (process .getInputStream ());
@@ -126,14 +135,20 @@ private String runCwltoolOnWorkflow(String argument, String workflowUrl)
126
135
int exitCode = process .waitFor ();
127
136
if (exitCode == 0 ) {
128
137
inputGobbler .join ();
138
+ process .destroyForcibly ();
129
139
return inputGobbler .getContent ();
130
140
} else {
131
141
errorGobbler .join ();
142
+ process .destroyForcibly ();
132
143
throw new CWLValidationException (errorGobbler .getContent ());
133
144
}
134
145
} catch (IOException | InterruptedException e ) {
135
146
logger .error ("Error running cwltool process" , e );
136
147
throw new CWLValidationException ("Error running cwltool process" );
148
+ } finally {
149
+ if (process != null ) {
150
+ process .destroyForcibly ();
151
+ }
137
152
}
138
153
}
139
154
}
0 commit comments