Skip to content

fix(pool): release prepared statements after reset failures - #6744

Open
wozhenbang2004 wants to merge 2 commits into
alibaba:masterfrom
wozhenbang2004:fix/ps-cache-reset-failure-6743
Open

wozhenbang2004 wants to merge 2 commits into
alibaba:masterfrom
wozhenbang2004:fix/ps-cache-reset-failure-6743

Conversation

@wozhenbang2004

Copy link
Copy Markdown

Fixes #6743.

When a pooled prepared statement throws from clearParameters() or clearBatch(), exception handling currently throws before the statement is closed or returned to the cache. Returning the connection retries the same failing cleanup and then drops its trace, leaving the raw statement open until the physical connection closes.

Release the wrapper and its result sets before reporting the original reset exception. Close new statements directly and evict cached statements through the existing pool path. Remember reset failure on the shared holder so another wrapper cannot put it back into the cache; defer its physical close until the last reference is released. Preserve a secondary direct-close exception as suppressed and report it to the exception sorter so a fatal close failure can still discard the connection.

Add 11 regressions for both reset methods, new and cached statements, shared holders, same-SQL replacement, duplicate close, result-set cleanup, and reset/close exception handling.

Validation

Base: fa8dc9912637a2f729eef9f55356621fec18d40e (master).

  • Compiled the two changed production classes and the selected test classes with OpenJDK 17.0.20 and javac --release 8. Other production classes came from the official Druid 1.2.28 artifact; this is a focused source-overlay test, not a full reactor build.
  • Baseline: 17 existing tests passed and all 11 new regressions failed. Patched: all 28 tests passed, with no skips.
  • Repeated the issue's 200-iteration fake-driver reproduction. While the pool was still open, baseline created/closed statements were 200/0; patched were 200/200. Error count decreased from 400 to 200 because connection return no longer retries the failed wrapper.
  • Checkstyle 9.3 with the repository's src/checkstyle/druid-checks.xml: all three changed files passed.
  • The standard Maven core command was attempted but did not reach compilation because the Java process could not connect to the session proxy. Full Maven core tests and upstream CI remain unverified.

Scope notes

Existing cache accounting for already-evicted holders and fatal shared-connection disposal needs a separate follow-up. Cache eviction retains its existing best-effort raw-close behavior; strict recovery from a non-fatal driver close failure is also outside this patch. The fatal-close regression above covers the direct-close path.

@CLAassistant

CLAassistant commented Nov 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants