Skip to content

Conversation

@ruanwenjun
Copy link
Member

@ruanwenjun ruanwenjun commented Dec 31, 2025

Why are the changes needed?

close #7290
When we close a kyuubi session, if the engine session(thrift client) has not initialized, then the kyuubi session will be closed, but the engine session might be alive, then will result in a resource leak.

How was this patch tested?

Can be tested by when the engine pod is pending, and then kill the jdbc client, the driver pod should be killed after initialized, but not.

Was this patch authored or co-authored using generative AI tooling?

NO

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2025

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (eecdaaa) to head (142a210).

Files with missing lines Patch % Lines
...la/org/apache/kyuubi/session/AbstractSession.scala 0.00% 7 Missing ⚠️
.../org/apache/kyuubi/session/KyuubiSessionImpl.scala 0.00% 4 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master   #7294   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files         698     698           
  Lines       43636   43646   +10     
  Branches     5893    5894    +1     
======================================
- Misses      43636   43646   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pan3793
Copy link
Member

pan3793 commented Dec 31, 2025

the idea makes sense to me

@ruanwenjun ruanwenjun changed the title [KYUUBI #7290] Fix the engine session might still alive when kyuubi session has been closed [KYUUBI #7290] Prevent engine session leak after Kyuubi session closed Dec 31, 2025
@ruanwenjun ruanwenjun requested a review from pan3793 January 1, 2026 00:01
@cxzl25 cxzl25 requested a review from Copilot January 3, 2026 05:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a resource leak issue where an engine session could remain active after the Kyuubi session was closed, specifically when the Kyuubi session is closed during the engine session initialization process.

Key Changes:

  • Added isClosed method to the Session trait to track session closure state
  • Implemented the isClosed check in AbstractSession using a volatile boolean flag
  • Added a check in KyuubiSessionImpl after engine session initialization to detect if the Kyuubi session was closed during initialization and throw an exception to trigger cleanup

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
kyuubi-common/src/main/scala/org/apache/kyuubi/session/Session.scala Added isClosed method signature to the Session trait
kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala Implemented isClosed method with a @volatile boolean flag and added idempotent close logic
kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala Added isClosed check after engine session opening to prevent resource leak when Kyuubi session is closed during engine initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (isClosed) {
throw KyuubiSQLException(s"KyuubiSession $handle has been closed")
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This critical race condition fix lacks automated test coverage. Consider adding a test that simulates closing a Kyuubi session while the engine session is being initialized to verify that the engine session is properly cleaned up. This could be done by using a mock or by introducing a delay in the engine session opening process during the test.

Copilot uses AI. Check for mistakes.
@ruanwenjun
Copy link
Member Author

Hi @pan3793, please help re-run the timeout test case. Thanks!

@pan3793 pan3793 added this to the v1.10.4 milestone Jan 5, 2026
@pan3793 pan3793 closed this in 8bed9de Jan 5, 2026
pan3793 pushed a commit that referenced this pull request Jan 5, 2026
### Why are the changes needed?
close #7290
When we close a kyuubi session, if the engine session(thrift client) has not initialized, then the kyuubi session will be closed, but the engine session might be alive, then will result in a resource leak.

### How was this patch tested?
Can be tested by when the engine pod is pending, and then kill the jdbc client, the driver pod should be killed after initialized.

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes #7294 from ruanwenjun/dev_wenjun_fix7290.

Closes #7290

142a210 [ruanwenjun] make sure the client closed
9745206 [ruanwenjun] set shouldRetry to false
d3c8608 [ruanwenjun] remove unused comment
866126d [ruanwenjun] If the session already closed, then return
3b2ee39 [ruanwenjun] [KYUUBI #7290] Fix the engine session might still alive when kyuubi session has been closed

Authored-by: ruanwenjun <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
(cherry picked from commit 8bed9de)
Signed-off-by: Cheng Pan <[email protected]>
pan3793 pushed a commit that referenced this pull request Jan 5, 2026
### Why are the changes needed?
close #7290
When we close a kyuubi session, if the engine session(thrift client) has not initialized, then the kyuubi session will be closed, but the engine session might be alive, then will result in a resource leak.

### How was this patch tested?
Can be tested by when the engine pod is pending, and then kill the jdbc client, the driver pod should be killed after initialized.

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes #7294 from ruanwenjun/dev_wenjun_fix7290.

Closes #7290

142a210 [ruanwenjun] make sure the client closed
9745206 [ruanwenjun] set shouldRetry to false
d3c8608 [ruanwenjun] remove unused comment
866126d [ruanwenjun] If the session already closed, then return
3b2ee39 [ruanwenjun] [KYUUBI #7290] Fix the engine session might still alive when kyuubi session has been closed

Authored-by: ruanwenjun <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
(cherry picked from commit 8bed9de)
Signed-off-by: Cheng Pan <[email protected]>
@pan3793
Copy link
Member

pan3793 commented Jan 5, 2026

thanks, merged to master/1.11.1/1.10.4

@ruanwenjun ruanwenjun deleted the dev_wenjun_fix7290 branch January 5, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Spark engine might not stop when the kyuubi session is closed.

4 participants