pan3793 commented on code in PR #5111:
URL: https://github.com/apache/kyuubi/pull/5111#discussion_r1279226046
##########
kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java:
##########
@@ -981,6 +986,43 @@ public void close() throws SQLException {
}
}
+ /**
+ * close the connection within timeout forcibly
+ *
+ * @param closeTimeout timeout for closing connection in seconds
+ * @throws SQLException
+ */
+ public void close(int closeTimeout) throws SQLException {
+ checkArgument(closeTimeout > 0, "closeTimeout must be greater than 0");
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ try {
+ SimpleTimeLimiter.create(executor)
+ .runWithTimeout(
+ () -> {
+ if (!isClosed) {
+ TCloseSessionReq closeReq = new TCloseSessionReq(sessHandle);
+ try {
+ client.CloseSession(closeReq);
+ } catch (TException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ },
+ closeTimeout,
+ TimeUnit.SECONDS);
+ } catch (Exception e) {
+ LOG.error("Error while closing connection with in timeout", e);
+ } finally {
+ executor.shutdownNow();
Review Comment:
I don't think it works, the body of runWithTimeout runs in another thread,
which means the current thread would reach this line soon.
BTW, I don't think we should add such a method at the JDBC driver level,
it's the caller's responsibility to cancel after a certain time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]