[SPARK-56466][CONNECT] Make SparkSession.close() idempotent#55333
Closed
zhengruifeng wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-56466][CONNECT] Make SparkSession.close() idempotent#55333zhengruifeng wants to merge 1 commit intoapache:masterfrom
zhengruifeng wants to merge 1 commit intoapache:masterfrom
Conversation
Co-authored-by: Isaac
8bef88c to
c4514dc
Compare
HyukjinKwon
approved these changes
Apr 14, 2026
Member
|
Merged to master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Make
spark.stop()idempotent on the client side so that calling it twice (e.g., user code calls it, then the platform calls it during cleanup) does not hang or fail.Client side (
SparkSession.close()):releaseLockandreleasedflag. AfterreleaseSession()completes (success or caught failure), the flag is set. On a second call, the flag gates the method and skips the RPC — since receiving aReleaseSessionResponsealready confirms server-side cleanup.client.shutdown()andallocator.close()in try-catch inside the synchronized block.Server side: already handles duplicate release requests gracefully —
closeSession()is a no-op when the session does not exist.Root cause of the hang: Without the
releasedguard, the secondclose()callsreleaseSession()on the already-shutdown gRPC channel. The channel returnsUNAVAILABLE, which the default retry policy retries up to 15 times with exponential backoff (~10 minutes total).Why are the changes needed?
When
spark.stop()is called twice (which happens in real-world cleanup scenarios), the second call hangs for ~10 minutes due to gRPC retries on the already-shutdown channel. This makesclose()idempotent and safe to call multiple times.Does this PR introduce any user-facing change?
No. This is a bug fix —
spark.stop()now completes immediately on a second call instead of hanging.How was this patch tested?
Added
SparkSessionCloseE2ESuitewith test"double stop should not retry releaseSession"— creates a session with a gRPC interceptor that countsReleaseSessioncalls, stops it twice, and verifies the second stop does not issue anotherreleaseSessionRPC.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-4-6)