diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/LaunchMapper.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/LaunchMapper.java index 100a504..b39a246 100644 --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/LaunchMapper.java +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/LaunchMapper.java @@ -33,6 +33,7 @@ import org.apache.hive.hcatalog.templeton.LauncherDelegator; import java.io.BufferedReader; +import java.io.FilterOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -186,6 +187,7 @@ public void run(Context context) throws IOException, InterruptedException { keepAlive.sendReport = false; pool.shutdown(); if (!pool.awaitTermination(WATCHER_TIMEOUT_SECS, TimeUnit.SECONDS)) { + System.err.println("Shutting down watcher/keep alive thread pool forcefully"); pool.shutdownNow(); } @@ -235,6 +237,17 @@ private void writeExitValue(Configuration conf, int exitValue, String statusdir) } } + private static class NonClosableStream extends FilterOutputStream { + public NonClosableStream(OutputStream out) { + super(out); + } + @Override + // override the close function not closing the stream + // to prevent closing System.out/System.err by mistake + public void close() throws IOException{ + //do nothing here + } + } private static class Watcher implements Runnable { private final InputStream in; @@ -250,9 +263,11 @@ public Watcher(Configuration conf, JobID jobid, InputStream in, String statusdir this.in = in; if (name.equals(STDERR_FNAME)) { - out = System.err; + // prevent System.err get closed by mistake + out = new NonClosableStream(System.err); } else { - out = System.out; + // prevent System.out get closed by mistake + out = new NonClosableStream(System.out); } if (TempletonUtils.isset(statusdir)) { @@ -305,6 +320,7 @@ public void run() { } } writer.flush(); + writer.close(); if(out != System.err && out != System.out) { //depending on FileSystem implementation flush() may or may not do anything writer.close();