[SPARK-58932][SS] Close the accepted socket in TransformWithStateInPySparkStateServer - #58205
Open
j1wonpark wants to merge 1 commit into
Open
[SPARK-58932][SS] Close the accepted socket in TransformWithStateInPySparkStateServer#58205j1wonpark wants to merge 1 commit into
j1wonpark wants to merge 1 commit into
Conversation
…SparkStateServer ### What changes were proposed in this pull request? Run the request loop of `TransformWithStateInPySparkStateServer.run()` inside `Utils.tryWithResource` so the socket returned by `stateServerSocket.accept()` is always closed. ### Why are the changes needed? `run()` accepts a connection from the Python worker but never closes it. The task completion listener closes only the listening `ServerSocketChannel`, so the accepted connection's file descriptor is held until the executor exits. `initStateServer()` binds an ephemeral port per task, so a long-running streaming query leaks one socket per task. Once the ephemeral port range is exhausted, every new connection on that executor fails with `java.net.BindException: Cannot assign requested address`, which also takes down unrelated connections such as the Kafka source. The loop has several early returns, so the close has to be tied to the scope. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Two tests added to `TransformWithStateInPySparkStateServerSuite`, covering the path where the request loop is never entered and the EOF early-return path. Both fail without the fix. The suite previously had no test calling `run()`. ### Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Opus 5 Signed-off-by: Jiwon Park <jpark92@outlook.kr>
j1wonpark
force-pushed
the
tws-state-server-socket-leak
branch
from
August 21, 2026 14:05
2334021 to
9f7e7ba
Compare
uros-b
approved these changes
Aug 21, 2026
Member
|
Thank you @j1wonpark! |
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?
Run the request loop of
TransformWithStateInPySparkStateServer.run()insideUtils.tryWithResourceso the socket returned bystateServerSocket.accept()is always closed.Why are the changes needed?
run()accepts a connection from the Python worker but never closes it. The task completion listener closes only the listeningServerSocketChannel, so the accepted connection's file descriptor is held until the executor exits.initStateServer()binds an ephemeral port per task, so a long-running streaming query leaks one socket per task. Once the ephemeral port range is exhausted, every new connection on that executor fails withjava.net.BindException: Cannot assign requested address, which also takes down unrelated connections such as the Kafka source.The loop has several early returns, so the close has to be tied to the scope.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Two tests added to
TransformWithStateInPySparkStateServerSuite, covering the path where the request loop is never entered and the EOF early-return path. Both fail without the fix. The suite previously had no test callingrun().Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: Claude Opus 5