raghav-reglobe opened a new issue, #70339:
URL: https://github.com/apache/doris/issues/70339

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Version
   
   master (d9d60bee9fe) and every branch carrying COM_CHANGE_USER support 
(#40932).
   
   ### What's Wrong?
   
   `max_user_connections` leaks a slot of the original user for every 
connection that changed its identity before closing, until that user is refused 
on every login with no session of theirs open; the user it switched to is 
driven below zero.
   
   `ConnectPoolMgr.registerConnection` counts the connection against 
`ctx.getQualifiedUser()` at login. `MysqlConnectProcessor.handleChangeUser` 
(COM_CHANGE_USER) later calls `ctx.setCurrentUserIdentity(...)`. 
`ConnectPoolMgr.unregisterConnection` then decrements 
`connByUser.get(ctx.getQualifiedUser())` — the identity at close time, i.e. the 
new user — so the original user's counter is never released. Any other path 
that swaps the context's current identity has the same effect.
   
   The refusal makes it hard to diagnose: `Reach limit of connections. Total: 
%d, User: %d, Current: %d` prints the frontend-wide connection count as 
`Current`, so a user refused by a leaked counter is shown e.g. `User: 2, 
Current: 0`.
   
   ### What You Expected?
   
   The counter a connection took at registration is released when it closes, 
whatever user it is at that time; and the refusal names the user's own count 
when it is the user's limit that refused.
   
   ### How to Reproduce?
   
   1. `CREATE USER u1 IDENTIFIED BY 'p1'; CREATE USER u2 IDENTIFIED BY 'p2'; 
SET PROPERTY FOR 'u1' 'max_user_connections' = '2';`
   2. Three times: open a connection as `u1`, send COM_CHANGE_USER to `u2` 
(e.g. Python `mysql.connector`: `cnx.cmd_change_user(username='u2', 
password='p2')`, or Connector/J `changeUser`), close it.
   3. Connect as `u1`: on the third iteration already, and on every later 
attempt, the login is refused `Reach limit of connections. Total: …, User: 2, 
Current: 0` although no `u1` session exists; it stays refused until the FE 
restarts. The FE metric `doris_fe_connection_total{user="u2"}` reads negative.
   
   ### Anything Else?
   
   A fix (record the counted user per connection id and release that one; 
append `User current: N` to the refusal when the user's own limit refused) 
follows in a PR.
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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]

  • [I] [Bug] max_user_connections l... raghav-reglobe (via GitHub) via commits

Reply via email to