PreparedStatement.setQueryTimeout() not honored in ClickHouse JDBC driver (version 0.9.1-all)
Description
When setQueryTimeout() is applied to a PreparedStatement, the timeout is not honored during query execution. Even if the query exceeds the configured timeout value, it continues to run until completion or manual termination.
This behavior is observed with the ClickHouse JDBC driver 0.9.1 (classifier: all).
Steps to Reproduce
- Configure a ClickHouse JDBC connection using version 0.9.1-all.
- Create a long-running query (e.g., SELECT sleep(3)).
- Use PreparedStatement.setQueryTimeout(1) to set a 1-second timeout.
- Execute the query.
Error Log or Exception StackTrace
No exception or timeout is thrown. The query runs to completion, ignoring the configured timeout.
Expected Behaviour The query should stop execution after the specified timeout period and throw an SQLTimeoutException.
Code Example
try (Connection connection = DriverManager.getConnection(url, user, password)) {
String sql = "SELECT sleep(3)"; // intentionally long query
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
stmt.setQueryTimeout(1); // set timeout to 1 seconds
long start = System.currentTimeMillis();
stmt.executeQuery();
long end = System.currentTimeMillis();
System.out.println("Query completed in " + (end - start) / 1000 + " seconds");
}
}catch (SQLTimeoutException te) {
System.err.println("Query timed out: " + te.getMessage());
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
Actual Result: The query runs for approximately 3 seconds. Expected Result: The query should terminate after around 1 seconds and throw an SQLTimeoutException.
Configuration
Client Configuration
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.9.1</version>
<classifier>all</classifier>
</dependency>
Environment
- [ ] Cloud Client version: java jdbc v2 0.9.2 and 0.9.1 Language version: Java 17 OS:
ClickHouse Server
- ClickHouse Server version:
- ClickHouse Server non-default settings, if any:
CREATE TABLEstatements for tables involved:- Sample data for all these tables, use clickhouse-obfuscator if necessary
Good day, @atish11pune !
We have implemented it only in https://github.com/ClickHouse/clickhouse-java/releases/tag/v0.9.2 However I see you mention 0.9.2 version too. Would you please upgrade to latest 0.9.3 and re-run tests. We will investigate on our side.
Thanks!
Good day, @atish11pune !
We have implemented it only in https://github.com/ClickHouse/clickhouse-java/releases/tag/v0.9.2 However I see you mention 0.9.2 version too. Would you please upgrade to latest 0.9.3 and re-run tests. We will investigate on our side.
Thanks!
Thanks for quick responce but, Tried with version 0.9.3 as well, but it did not work. Additionally, I don’t see any fix related to PreparedStatement.setQueryTimeout in the provided link.
[jdbc-v2] Implemented setNetworkTimeout of Connection interface. Used to fail fast when network operation fails. Related to stale connection problem.
This one I think relates to the issue.
We will investigate and fix. Thank you for the issue!
[jdbc-v2] Implemented setNetworkTimeout of Connection interface. Used to fail fast when network operation fails. Related to stale connection problem.
This one I think relates to the issue.
We will investigate and fix. Thank you for the issue!
Please confirm the release date of version 0.9.4.
@atish11pune
Usually we make release at the end of a month. However next release is not scheduled yet.