Skip to content

fix issue 20022#23740

Open
robll-v1 wants to merge 12 commits intomatrixorigin:mainfrom
robll-v1:issue/20022
Open

fix issue 20022#23740
robll-v1 wants to merge 12 commits intomatrixorigin:mainfrom
robll-v1:issue/20022

Conversation

@robll-v1
Copy link
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #20022

What this PR does / why we need it:

Problem
Under long-running load with proxy connection cache enabled, backend sessions (especially dump) kept accumulating, eventually causing login failures and instability.

Root Cause

QUIT handling was asynchronous (fire-and-forget), so cleanup was not guaranteed before the handler exited.
In handler defer logic, when connection cache was enabled, backend connections could be left open even if they were not successfully cached.
On EOF/connection-end paths (client disconnect without COM_QUIT), there was no explicit fallback cleanup.
Together, these paths leaked backend connections over time.
Fix

Make quit cleanup synchronous and idempotent in clientConn using sync.Once.
Track whether a backend connection was actually cached (cached flag).
In handler finalization:
keep backend connection only if it was successfully cached;
otherwise force cleanup via Quit() (fallback to Close()).
Add EOF/conn-end fallback cleanup by explicitly triggering the quit path once.
Why this is minimal

Changes are limited to proxy connection lifecycle/cleanup paths.
No changes to SQL execution, routing policy, or auth semantics.
Validation

Environment: local 2 CN + proxy, conn-cache enabled.
Workload: point_select_10_1000000_prepare, 300 terminals, 70 minutes.
Result: ERROR=0, SUCCEED.
dump connections stabilized (no continuous growth after warm-up), including past the previous ~57-minute failure window.
Repeated login checks succeeded; no panic observed.

@CLAassistant
Copy link

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.

@robll-v1 robll-v1 requested a review from heni02 as a code owner February 12, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants