diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index 30b6daf8f9..09e1a18d9e 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -48,6 +48,7 @@ import org.apache.http.client.CookieStore; import org.apache.http.client.HttpRequestRetryHandler; import org.apache.http.client.ServiceUnavailableRetryStrategy; +import org.apache.http.client.config.RequestConfig; import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.socket.ConnectionSocketFactory; @@ -113,6 +114,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.hive.jdbc.Utils.JdbcConnectionParams.CLIENT_SO_TIMEOUT_MILLIS; +import static org.apache.hive.jdbc.Utils.JdbcConnectionParams.CLIENT_SO_TIMEOUT_MILLIS_DEFAULT; + /** * HiveConnection. * @@ -515,7 +519,19 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte throw new SQLException(msg, " 08S01", e); } } - return httpClientBuilder.build(); + + final int timeout; + if (connParams.getSessionVars().containsKey(CLIENT_SO_TIMEOUT_MILLIS)) { + timeout = Integer.parseInt(connParams.getSessionVars().get(CLIENT_SO_TIMEOUT_MILLIS)); + } else { + timeout = CLIENT_SO_TIMEOUT_MILLIS_DEFAULT; + } + final RequestConfig config = RequestConfig.custom() + .setConnectTimeout(timeout) + .setConnectionRequestTimeout(timeout) + .setSocketTimeout(timeout).build(); + + return httpClientBuilder.setDefaultRequestConfig(config).build(); } /** diff --git a/jdbc/src/java/org/apache/hive/jdbc/Utils.java b/jdbc/src/java/org/apache/hive/jdbc/Utils.java index 42b3975975..752ad726b9 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/Utils.java +++ b/jdbc/src/java/org/apache/hive/jdbc/Utils.java @@ -101,6 +101,8 @@ // We're deprecating the name and placement of this in the parsed map (from hive conf vars to // hive session vars). static final String TRANSPORT_MODE_DEPRECATED = "hive.server2.transport.mode"; + static final String CLIENT_SO_TIMEOUT_MILLIS = "conn.timeout.millis"; + static final int CLIENT_SO_TIMEOUT_MILLIS_DEFAULT = 300000; public static final String TRANSPORT_MODE = "transportMode"; // We're deprecating the name and placement of this in the parsed map (from hive conf vars to // hive session vars).