Repository navigation
fix(jdbc-v2): throw on closed connection in commit, rollback, getCatalog, getNetworkTimeout, setClientInfo - #3281
Open
pcbeingused333 wants to merge 3 commits into
Conversation
…log, getNetworkTimeout, setClientInfo Fixes ClickHouse#3270 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
Contributor
|
@pcbeingused333 |
chernser
approved these changes
Oct 31, 2026
chernser
reviewed
Oct 31, 2026
| } | ||
|
|
||
| private void ensureOpenForClientInfo() throws SQLClientInfoException { | ||
| if (closed) { |
Contributor
There was a problem hiding this comment.
please change to isClosed() so both methods work same in the future.
Author
|
Done, This comment was drafted with Claude Code. |
chernser
reviewed
Oct 31, 2026
| } | ||
|
|
||
| private void ensureOpenForClientInfo() throws SQLClientInfoException { | ||
| boolean connectionClosed; |
Contributor
There was a problem hiding this comment.
this method should just throw another exception. This should work:
if (isClosed()) {
throw new SQLClientInfoException("Connection is closed",
ExceptionUtils.SQL_STATE_CONNECTION_EXCEPTION, Collections.emptyMap());
}
…declares SQLException
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3270
After
Connection#close(), several jdbc-v2ConnectionImplmethods did not check the connection state:getCatalog()andgetNetworkTimeout()returned values,setClientInfo(...)updated state, andcommit()/rollback()only reported the unsupported feature (and did nothing withjdbc_ignore_unsupported_values=true). The JDBC contract requires anSQLExceptionon a closed connection.ensureOpen()is now the first statement ofcommit(),rollback(),getCatalog()andgetNetworkTimeout(). BothsetClientInfooverloads only declareSQLClientInfoException, so they use a small helper that throws it with the same message and SQLState (08000) asensureOpen().close(),abort(),isClosed()andisValid()are unchanged.Compatibility: Calls on an already closed connection now throw instead of returning silently. Code that relied on those calls succeeding after
close()would now see an exception; open connections are unaffected. Ahistory/latest/3270.mdentry is included.Note: #3266 touches the body of
getNetworkTimeout(); the overlap is a one-line addition at the top of the method.Test:
ConnectionTest#testClosedConnectionThrowscloses a connection (with defaults and withjdbc_ignore_unsupported_values=true) and asserts each method throws, whileclose(),isClosed()andisValid()stay allowed. It fails on main (nothing thrown) and passes with the fix, against a ClickHouse server.Checklist
This change was prepared with the assistance of an AI coding tool (Claude Code) and reviewed before submission.
🤖 Generated with Claude Code
Note
Medium Risk
Behavior change on closed connections may break code that relied on silent no-ops, but open-connection behavior is unchanged and aligns with the JDBC contract.
Overview
Fixes #3270 by enforcing JDBC behavior after
Connection#close()in jdbc-v2ConnectionImpl.commit(),rollback(),getCatalog(), andgetNetworkTimeout()now callensureOpen()first, so a closed connection raisesSQLExceptionwith SQLState08000("Connection is closed") instead of returning values or only hitting the unsupported-feature path (including whenjdbc_ignore_unsupported_values=true).Both
setClientInfooverloads use a newensureOpenForClientInfo()helper that throwsSQLClientInfoExceptionwith the same message and SQLState.isClosed()no longer declaresthrows SQLException, matching theConnectioninterface.close(),isValid(), and related lifecycle behavior are unchanged.Adds
ConnectionTest#testClosedConnectionThrows(with and without ignore-unsupported) and ahistory/latest/3270.mdchangelog note. Compatibility: callers that invoked these methods on an already-closed connection will now get exceptions instead of silent success.Reviewed by Cursor Bugbot for commit 8040bc3. Bugbot is set up for automated code reviews on this repo. Configure here.