Skip to content

Commit

Permalink
Fixed issue lsc-project#10 : LSC process hangs indefinitely when oupu…
Browse files Browse the repository at this point in the history
…t overflow the available buffer.
  • Loading branch information
soisik committed Mar 5, 2019
1 parent bb0727e commit c3bba4f
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.lsc.plugins.connectors.executable;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -130,28 +132,26 @@ private int execute(String[] runtime, String[] env, String input, StringBuffer d
outputStream.flush();
outputStream.close();

BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
datas.append(line + System.getProperty("line.separator"));
}

//TODO: need to check for max time
LOGGER.debug("Waiting for command to stop ... ");

p.waitFor();
} catch (IOException e) {
// Encountered an error while reading data from output
LOGGER.error("Encountered an I/O exception while writing data to script {}", runtime);
LOGGER.error("Encountered an I/O exception while writing/reading data to/from script {}", runtime);
LOGGER.error(e.toString(), e);
} catch (InterruptedException e) {
// Encountered an interruption
LOGGER.error("Script {} interrupted", runtime);
LOGGER.debug(e.toString(), e);
}

try {
datas.append(IOUtils.toString(p.getInputStream()));
} catch (IOException e) {
// Failing to read the complete string causes null return
LOGGER.error("Fail to read complete data from script output stream: {}", runtime);
LOGGER.debug(e.toString(), e);
}

try {
messages.append(IOUtils.toString(p.getErrorStream()));
} catch (IOException e) {
Expand Down

0 comments on commit c3bba4f

Please sign in to comment.