diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
index f86d6a7..10dbeb6 100644
--- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
+++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
@@ -645,6 +645,12 @@ public class HiveConf extends Configuration {
* This will be removed once the rest of the DML changes are committed.
*/
HIVE_INTERNAL_DDL_LIST_BUCKETING_ENABLE("hive.internal.ddl.list.bucketing.enable", false),
+
+ // Allow TCP Keep alive socket option for for HiveServer or a maximum timeout for the socket.
+
+ SERVER_READ_SOCKET_TIMEOUT("hive.server.read.socket.timeout", 10),
+ SERVER_TCP_KEEP_ALIVE("hive.server.tcp.keepalive", true),
+
;
public final String varname;
diff --git conf/hive-default.xml.template conf/hive-default.xml.template
index 4a59fb6..7d19e32 100644
--- conf/hive-default.xml.template
+++ conf/hive-default.xml.template
@@ -1491,5 +1491,19 @@
The number of miliseconds between HMSHandler retry attempts
+
+
+ hive.server.read.socket.timeout
+ 10
+ Timeout for the HiveServer to close the connection if no response from the client in N seconds, defaults to 10 seconds.
+
+
+
+ hive.server.tcp.keepalive
+ true
+ Whether to enable TCP keepalive for the Hive server. Keepalive will prevent accumulation of half-open connections.
+
+
+
diff --git service/src/java/org/apache/hadoop/hive/service/HiveServer.java service/src/java/org/apache/hadoop/hive/service/HiveServer.java
index 2b2f681..32729f2 100644
--- service/src/java/org/apache/hadoop/hive/service/HiveServer.java
+++ service/src/java/org/apache/hadoop/hive/service/HiveServer.java
@@ -42,6 +42,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStore;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.Schema;
+import org.apache.hadoop.hive.metastore.TServerSocketKeepAlive;
import org.apache.hadoop.hive.ql.CommandNeedRetryException;
import org.apache.hadoop.hive.ql.Driver;
import org.apache.hadoop.hive.ql.plan.api.QueryPlan;
@@ -651,6 +652,7 @@ public class HiveServer extends ThriftHive {
cli.parse(args);
+
// NOTE: It is critical to do this prior to initializing log4j, otherwise
// any log specific settings via hiveconf will be ignored
Properties hiveconf = cli.addHiveconfToSystemProperties();
@@ -665,7 +667,11 @@ public class HiveServer extends ThriftHive {
HiveConf conf = new HiveConf(HiveServerHandler.class);
ServerUtils.cleanUpScratchDir(conf);
- TServerTransport serverTransport = new TServerSocket(cli.port);
+
+
+ boolean tcpKeepAlive = conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE);
+
+ TServerTransport serverTransport = tcpKeepAlive ? new TServerSocketKeepAlive(cli.port) : new TServerSocket(cli.port, 1000 * conf.getIntVar(HiveConf.ConfVars.SERVER_READ_SOCKET_TIMEOUT));
// set all properties specified on the command line
for (Map.Entry