[SPARK-58932][SS][4.1] Close the accepted socket in TransformWithStateInPySparkStateServer - #58309
Closed
j1wonpark wants to merge 1 commit into
Closed
[SPARK-58932][SS][4.1] Close the accepted socket in TransformWithStateInPySparkStateServer#58309j1wonpark wants to merge 1 commit into
j1wonpark wants to merge 1 commit into
Conversation
…SparkStateServer Run the request loop of `TransformWithStateInPySparkStateServer.run()` inside `Utils.tryWithResource` so the socket returned by `stateServerSocket.accept()` is always closed. `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. No. 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()`. Yes. Generated-by: Claude Opus 5 Closes apache#58205 from j1wonpark/tws-state-server-socket-leak. Authored-by: Jiwon Park <jpark92@outlook.kr> Signed-off-by: Jungtaek Lim <kabhwan.opensource@gmail.com> (cherry picked from commit c5fbdf7)
Contributor
|
Merged via #58308 |
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?
Backport of #58205 to branch-4.1: run the request loop of
TransformWithStateInPySparkStateServer.run()insideUtils.tryWithResourceso the accepted socket is always closed. This branch does not have SPARK-58977, so unlike master theaccept()call is unchanged.Why are the changes needed?
The accepted socket is never closed, leaking one file descriptor per task until the executor exhausts the ephemeral port range (
java.net.BindException). See #58205 for details.Does this PR introduce any user-facing change?
No.
How was this patch tested?
The two tests added in #58205 are included;
TransformWithStateInPySparkStateServerSuitepasses locally on this branch.Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: Claude Opus 5