Index: 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 (revision 1552388) +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/LaunchMapper.java (working copy) @@ -241,6 +241,7 @@ private OutputStream out; private final JobID jobid; private final Configuration conf; + boolean needCloseOutput = false; public Watcher(Configuration conf, JobID jobid, InputStream in, String statusdir, String name) throws IOException { @@ -258,16 +259,18 @@ Path p = new Path(statusdir, name); FileSystem fs = p.getFileSystem(conf); out = fs.create(p); + needCloseOutput = true; LOG.info("templeton: Writing status to " + p); } } @Override public void run() { + PrintWriter writer = null; try { InputStreamReader isr = new InputStreamReader(in); BufferedReader reader = new BufferedReader(isr); - PrintWriter writer = new PrintWriter(out); + writer = new PrintWriter(out); String line; while ((line = reader.readLine()) != null) { @@ -308,6 +311,15 @@ } } catch (IOException e) { LOG.error("templeton: execute error: ", e); + } finally { + // Need to close() because in some FileSystem + // implementations flush() is no-op. + // Close the file handle if it is a hdfs file. + // But if it is stderr/stdout, skip it since + // WebHCat is not supposed to close it + if (needCloseOutput && writer!=null) { + writer.close(); + } } } }