You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "Chaho12 (via GitHub)" <gi...@apache.org> on 2026/09/22 09:08:52 UTC
[PR] [KYUUBI ##7759] Reduce the connection limit count when session creation fails [kyuubi]
Chaho12 opened a new pull request, #7760:
URL: https://github.com/apache/kyuubi/pull/7760
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/master/contributing/code/index.html
2. If the PR is related to an issue in https://github.com/apache/kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new feature, clarify the use cases.
2. If you fix a bug, you can clarify why it is a bug, and what versions are affected.
-->
`KyuubiSessionManager.openSession` takes a count from the session limiter before the session is
opened, and `closeSession` is the only place that gives one back.
`SessionManager.openSession` calls `createSession` outside the `try` whose `catch` calls
`closeSession`, and `AbstractSession.normalizedConf` is a `val`, so a session whose conf fails
validation dies in the constructor and is never registered in `handleToSession`. `closeSession`
never runs for it, and the count is kept for good.
Once as many opens have failed as `kyuubi.server.limit.connections.per.user` allows, every further
open from that user is rejected by the limiter although the user holds no session, until the
server restarts. `kyuubi.server.limit.connections.per.ipaddress` leaks the same way.
Ordinary client configuration reaches this on a server that follows the documented
`kyuubi.session.conf.restrict.list` guidance: `spark.sql.extensions` is in the example restrict
list in the [session configuration docs](https://kyuubi.readthedocs.io/en/master/security/session_configuration.html),
and a client that keeps sending it locks its own account out. We hit this in production - three
server nodes each rejected 20 opens for the restricted key, after which every open from that user
failed with the connection-limit message while `kyuubi_connection_opened` stayed 0, and a rolling
restart was the only way to recover.
Affects master and 1.11.1. Batch sessions are not affected: `openBatchSession` takes its count
after the session is built and inside the `try` that closes it.
close #7759
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
Added `KyuubiSessionManagerLimiterSuite`, which sets `kyuubi.server.limit.connections.per.user=2`
and a restrict list, then opens `limit + 2` sessions carrying the restricted key and asserts every
attempt is still rejected by the restrict list rather than by the limiter.
build/mvn test -pl kyuubi-server -am -Dtest=none \
-DwildcardSuites=org.apache.kyuubi.session.KyuubiSessionManagerLimiterSuite
Negative check: with the change reverted, the suite fails on the third attempt with
`"Connection limit per user reached (user: user limit: 2)" did not contain
"spark.sql.extensions is a restrict key"`, which is the production symptom.
### Was this patch assisted by generative AI tooling?
<!--
If generative AI tooling has assisted in authoring or reviewing this patch, please include
an 'Assisted-by: ' trailer that identifies the agent and/or model.
For example: 'Assisted-by: Claude Opus 4.7' or 'Assisted-by: Claude:claude-opus-4-7'.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
Assisted-by: Claude Opus 5
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
Re: [PR] [KYUUBI #7759] Reduce the connection limit count when session creation fails [kyuubi]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 closed pull request #7760: [KYUUBI #7759] Reduce the connection limit count when session creation fails
URL: https://github.com/apache/kyuubi/pull/7760
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
Re: [PR] [KYUUBI #7759] Reduce the connection limit count when session creation fails [kyuubi]
Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on PR #7760:
URL: https://github.com/apache/kyuubi/pull/7760#issuecomment-5793070893
Thanks for your contribution; I prefer handling exceptions within `openSession`, like this:
```
override def openSession(
protocol: TProtocolVersion,
user: String,
password: String,
ipAddress: String,
conf: Map[String, String]): SessionHandle = {
val username = Option(user).filter(_.nonEmpty).getOrElse("anonymous")
limiter.foreach(_.increment(UserIpAddress(username, ipAddress)))
var handle: SessionHandle = null
try {
handle = super.openSession(protocol, username, password, ipAddress, conf)
handle
} catch {
case e: Throwable =>
MetricsSystem.tracing { ms =>
ms.incCount(CONN_FAIL)
ms.incCount(MetricRegistry.name(CONN_FAIL, user))
ms.incCount(MetricRegistry.name(CONN_FAIL, SessionType.INTERACTIVE.toString))
}
// If the session handle is null, closeSession(handle) will not be called,
// so we need to decrement the limiter here.
if (handle == null) {
limiter.foreach(_.decrement(UserIpAddress(username, ipAddress)))
}
throw KyuubiSQLException(
s"Error opening session for $username client ip $ipAddress, due to ${e.getMessage}",
e)
}
}
```
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
Re: [PR] [KYUUBI #7759] Reduce the connection limit count when session creation fails [kyuubi]
Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #7760:
URL: https://github.com/apache/kyuubi/pull/7760#issuecomment-6458488315
**Merge Summary:**
- merged into master https://github.com/apache/kyuubi/commit/a4f61c4b15b784a6037c00ecfdb291d5563d0c70
- merged into branch-1.12 https://github.com/apache/kyuubi/commit/903bd5de2882c468040cf8fbb89eab29b9c30c62
- merged into branch-1.11 https://github.com/apache/kyuubi/commit/d6f6ba786393473370effdadb079b52fb8237c8a
*Posted by `merge_kyuubi_pr.py`*
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
Re: [PR] [KYUUBI #7759] Reduce the connection limit count when session creation fails [kyuubi]
Posted by "Chaho12 (via GitHub)" <gi...@apache.org>.
Chaho12 commented on PR #7760:
URL: https://github.com/apache/kyuubi/pull/7760#issuecomment-5903419555
@wForget The reason why i didn't put this in openSession is because if it fails after setSession, SessionManager.openSession already calls closeSession, so if i put it at openSession, then it would reduce twice.
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org