Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java (revision 1148194) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java (working copy) @@ -22,6 +22,7 @@ import org.apache.hadoop.hive.service.HiveClient; import org.apache.hadoop.hive.service.HiveInterface; import org.apache.hadoop.hive.service.HiveServer; +import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; @@ -126,12 +127,17 @@ */ public void close() throws SQLException { - try { - if (transport != null) { - transport.close(); + if (!isClosed) { + try { + client.clean(); + } catch (TException e) { + throw new SQLException("Error while cleaning up the server resources", e); + } finally { + isClosed = true; + if (transport != null) { + transport.close(); + } } - } finally { - isClosed = true; } } Index: service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java =================================================================== --- service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java (revision 1148194) +++ service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java (working copy) @@ -88,6 +88,11 @@ protected void tearDown() throws Exception { super.tearDown(); if (standAloneServer) { + try { + client.clean(); + } catch (Exception e) { + e.printStackTrace(); + } transport.close(); } }