Chaho12 opened a new issue, #7804:
URL: https://github.com/apache/kyuubi/issues/7804

   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   
   
   ### Search before asking
   
   - [x] I have searched in the 
[issues](https://github.com/apache/kyuubi/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Describe the bug
   
   `KyuubiSessionManager` gives back session limiter counts that the session 
never took, in two ways.
   The `ipaddress` and `user:ipaddress` counters are shared, so each extra 
give-back frees a place
   that another open session holds, and the connection limits stop being 
enforced.
   
   **1. Unlimited users.** `SessionLimiterWithAccessControlListImpl.increment` 
does not count a user
   in `kyuubi.server.limit.connections.user.unlimited.list`, but `closeSession` 
decrements for every
   session. Each time an unlimited user closes a session, the counter of its 
client address drops by
   one. Since #7759, a session that fails while it is created does the same 
(the decrement in
   `KyuubiSessionManager.createSession`). Behind a gateway, where all users 
share one address, heavy
   unlimited traffic keeps that counter near 0, so 
`kyuubi.server.limit.connections.per.ipaddress` is
   in effect off.
   
   Deciding at close time from the unlimited list is not enough either: the 
list can be changed with
   `refresh/unlimited_users` while a session is open. A user who was counted at 
open and has become
   unlimited by close would then keep the count for good.
   
   **2. Concurrent close.** `KyuubiSessionManager.closeSession` looks up the 
session, then decrements
   in a `finally`. If two callers close the same session at once - the idle 
session checker, the
   engine alive checker and the client can all do it - both find it. The one 
that loses gets
   `Invalid SessionHandle` from `SessionManager.closeSession`, but still 
decrements, taking the count
   of another session from the same user or address.
   
   Steps to reproduce (1), with `per.ipaddress=2` and `unlimited.list=svc`, all 
from one address:
   
   1. `alice` and `bob` open one session each (the address is now full).
   2. `svc` opens a session and closes it.
   3. `carol` opens a session - it is let in, and three sessions are open on a 
limit of 2.
   
   ### Affects Version(s)
   
   master/1.11.1
   
   ### Kyuubi Server Log Output
   
   ```logtalk
   > No error is logged: the third session is let in where it should be 
rejected with
   > "Connection limit per ipaddress reached (ipaddress: <ip> limit: 2)".
   ```
   
   ### Kyuubi Engine Log Output
   
   ```logtalk
   > Not related to the engine
   ```
   
   ### Kyuubi Server Configurations
   
   ```yaml
   kyuubi.server.limit.connections.per.ipaddress           2
   kyuubi.server.limit.connections.user.unlimited.list     svc
   ```
   
   ### Kyuubi Engine Configurations
   
   ```yaml
   > Not related to the engine
   ```
   
   ### Additional context
   
   Fix proposal: let `SessionLimiter.increment` report whether it counted the 
session, record that on
   the session when it is opened, and give the count back only for a session 
that holds it. Taking the
   record with an atomic get-and-clear also makes the give-back happen once 
when the session is
   closed by several callers at once.
   
   Related: #7802 (a rejected open keeps the counts of keys counted before the 
rejecting key).
   
   ### Are you willing to submit PR?
   
   - [x] Yes. I would be willing to submit a PR with guidance from the Kyuubi 
community to fix.
   - [ ] No. I cannot submit a PR at this time.
   


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

Reply via email to