@@ -67,26 +67,33 @@ public String getVersion() {
6767 if (cwlToolVersion != null ) {
6868 return cwlToolVersion ;
6969 }
70+ Process process = null ;
7071 try {
7172 // Run cwltool --version
7273 String [] command = {"cwltool" , "--version" };
7374 ProcessBuilder cwlToolProcess = new ProcessBuilder (command );
74- Process process = cwlToolProcess .start ();
75+ process = cwlToolProcess .start ();
7576
7677 // Get input stream
7778 InputStream is = process .getInputStream ();
7879 InputStreamReader isr = new InputStreamReader (is );
7980 BufferedReader br = new BufferedReader (isr );
8081
8182 String line ;
83+ String cwlToolVersion ;
8284 if ((line = br .readLine ()) != null ) {
8385 cwlToolVersion = line .substring (line .indexOf (' ' ) + 1 );
84- return cwlToolVersion ;
8586 } else {
86- return "<error getting cwl version>" ;
87+ cwlToolVersion = "<error getting cwltool version>" ;
8788 }
89+ return cwlToolVersion ;
90+
8891 } 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+ }
9097 }
9198 }
9299
@@ -100,6 +107,8 @@ public String getVersion() {
100107 */
101108 private String runCwltoolOnWorkflow (String argument , String workflowUrl )
102109 throws CWLValidationException {
110+ Process process = null ;
111+
103112 try {
104113 // Run command
105114 String [] command = {
@@ -114,7 +123,7 @@ private String runCwltoolOnWorkflow(String argument, String workflowUrl)
114123 workflowUrl
115124 };
116125 ProcessBuilder cwlToolProcess = new ProcessBuilder (command );
117- Process process = cwlToolProcess .start ();
126+ process = cwlToolProcess .start ();
118127
119128 // Read output from the process using threads
120129 StreamGobbler inputGobbler = new StreamGobbler (process .getInputStream ());
@@ -126,14 +135,20 @@ private String runCwltoolOnWorkflow(String argument, String workflowUrl)
126135 int exitCode = process .waitFor ();
127136 if (exitCode == 0 ) {
128137 inputGobbler .join ();
138+ process .destroyForcibly ();
129139 return inputGobbler .getContent ();
130140 } else {
131141 errorGobbler .join ();
142+ process .destroyForcibly ();
132143 throw new CWLValidationException (errorGobbler .getContent ());
133144 }
134145 } catch (IOException | InterruptedException e ) {
135146 logger .error ("Error running cwltool process" , e );
136147 throw new CWLValidationException ("Error running cwltool process" );
148+ } finally {
149+ if (process != null ) {
150+ process .destroyForcibly ();
151+ }
137152 }
138153 }
139154}
0 commit comments