diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java index e2db0c7274..eb6e840df2 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java @@ -704,18 +704,20 @@ private void closeClient(TezClient client) throws TezException, protected final void cleanupScratchDir() throws IOException { if (tezScratchDir != null) { - FileSystem fs = tezScratchDir.getFileSystem(conf); - fs.delete(tezScratchDir, true); - tezScratchDir = null; + try (FileSystem fs = tezScratchDir.getFileSystem(conf)) { + fs.delete(tezScratchDir, true); + tezScratchDir = null; + } } } protected final void cleanupDagResources() throws IOException { LOG.info("Attemting to clean up resources for " + sessionId + ": " + resources); if (resources != null) { - FileSystem fs = resources.dagResourcesDir.getFileSystem(conf); - fs.delete(resources.dagResourcesDir, true); - resources = null; + try (FileSystem fs = resources.dagResourcesDir.getFileSystem(conf)) { + fs.delete(resources.dagResourcesDir, true); + resources = null; + } } } diff --git ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java index 88a8919d09..09f9204ee7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java @@ -47,6 +47,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.hadoop.conf.Configuration; @@ -904,6 +905,10 @@ private void dropPathAndUnregisterDeleteOnExit(Path path, Configuration conf, bo } catch (IllegalArgumentException | UnsupportedOperationException | IOException e) { LOG.error("Failed to delete path at {} on fs with scheme {}", path, (fs == null ? "Unknown-null" : fs.getScheme()), e); + } finally { + if (localFs) { + IOUtils.closeQuietly(fs); + } } }