raghav-reglobe opened a new pull request, #70341:
URL: https://github.com/apache/doris/pull/70341
### What problem does this PR solve?
Issue Number: close #70339
Problem Summary:
`ConnectPoolMgr.registerConnection` counts a connection against
`max_user_connections` of the user it logged in as; `unregisterConnection`
decremented `connByUser.get(ctx.getQualifiedUser())` at close time. A
connection whose identity changed while it lived (COM_CHANGE_USER, #40932)
therefore released the *new* user's counter: the original user leaked one slot
per switched connection until every one of its logins was refused with no
session of its own open, and the new user's counter went negative
(`doris_fe_connection_total{user=…}`).
The pool now records, per connection id, the user it counted, and
`unregisterConnection` releases that one (falling back to the context's user
for a connection registered before the map existed). The refusal also names the
user's own count when it is the user's limit that refused — `Reach limit of
connections. Total: 100, User: 2, Current: 3, User current: 2` — since
`Current` is the frontend-wide total and on its own reads as headroom the user
does not have; the text is unchanged otherwise.
### Release note
Fix `max_user_connections` leaking a slot of the original user for every
connection that changed user (COM_CHANGE_USER) before closing.
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [x] Unit Test
- [x] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
Unit: `ConnectPoolMgrTest` — a connection registered as one user and closed
as another releases the original user's counter (three rounds up to the limit,
then the limit still admits exactly `max_user_connections` and refuses the
next); the refusal text with and without the user's count.
`ConnectionExceedTest`'s user-limit refusal updated for the appended count.
Manual (a single-FE cloud cluster built from this change): user with
`max_user_connections=2` and PROXY_PRIV — two sessions held, the third refused
`… User: 2, Current: 2, User current: 2`; then eight sessions that each
switched identity and closed all connected (before the fix the third was
refused `User: 2, Current: 0` with no session open); afterwards again exactly
two held and the third refused.
- Behavior changed:
- [ ] No.
- [x] Yes. The refusal message gains `, User current: N` when the user's
own limit refused.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]