-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-53673][CONNECT][TESTS][4.0] Fix a flaky test failure in SparkSessionE2ESuite - interrupt tag caused by the usage of ForkJoinPool
#52476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
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
dongjoon-hyun
approved these changes
Sep 27, 2025
Member
dongjoon-hyun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM.
dongjoon-hyun
pushed a commit
that referenced
this pull request
Sep 27, 2025
…SessionE2ESuite - interrupt tag` caused by the usage of `ForkJoinPool` ### What changes were proposed in this pull request? This PR backports #52417 to `branch-4.0`. This PR aims to fix one of the issues which block SPARK-48139. In the problematic test `interrupt tag` in `SparkSessionE2ESuite`, four futures run on threads in `ForkJoinPool` and try to interrupt through tags. A thread in a `ForkJoinPool` can create a spare thread and make it available in the pool so any of threads can be parent and child. It can happen when a thread performs a blocking operation. One example is `ArrayBlockingQueue.take` and it is called in a method provided by [gRPC](https://github.com/grpc/grpc-java/blob/24085103b926559659ecd3941a3308479876f084/stub/src/main/java/io/grpc/stub/ClientCalls.java#L607). On the other hand, tags are implemented as [InheritableThreadLocal](https://github.com/apache/spark/blob/13e70100426233e62fd9edf13e229f91f4941ff8/sql/connect/common/src/main/scala/org/apache/spark/sql/connect/client/SparkConnectClient.scala#L285). So, if the futures q1 and q4, or q2 and q3 are parent and child, tags should be inherited, which causes the flaky test failure. You can easily reproduce the issue by inserting a sleep into the problematic test like as follows (don't forget to replace `ignore` with `test`). ``` // TODO(SPARK-48139): Re-enable `SparkSessionE2ESuite.interrupt tag` - ignore("interrupt tag") { + test("interrupt tag") { val session = spark import session.implicits._ -204,6 +204,7 class SparkSessionE2ESuite extends ConnectFunSuite with RemoteSparkSession { spark.clearTags() // clear for the case of thread reuse by another Future } }(executionContext) + Thread.sleep(1000) val q4 = Future { assert(spark.getTags() == Set()) spark.addTag("one") ``` And then, run the test. ``` $ build/sbt 'connect-client-jvm/testOnly org.apache.spark.sql.connect.SparkSessionE2ESuite -- -z "interrupt tag"' ``` ### Why are the changes needed? For test stability. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Ran the problematic test with inserting sleep like mentioned above and it passed. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #52476 from sarutak/fix-thread-pool-issue-4.0. Authored-by: Kousuke Saruta <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
Member
|
Merged to branch-4.0. |
Member
Author
|
Thank you, @dongjoon-hyun ! |
zifeif2
pushed a commit
to zifeif2/spark
that referenced
this pull request
Nov 14, 2025
…SessionE2ESuite - interrupt tag` caused by the usage of `ForkJoinPool` ### What changes were proposed in this pull request? This PR backports apache#52417 to `branch-4.0`. This PR aims to fix one of the issues which block SPARK-48139. In the problematic test `interrupt tag` in `SparkSessionE2ESuite`, four futures run on threads in `ForkJoinPool` and try to interrupt through tags. A thread in a `ForkJoinPool` can create a spare thread and make it available in the pool so any of threads can be parent and child. It can happen when a thread performs a blocking operation. One example is `ArrayBlockingQueue.take` and it is called in a method provided by [gRPC](https://github.com/grpc/grpc-java/blob/24085103b926559659ecd3941a3308479876f084/stub/src/main/java/io/grpc/stub/ClientCalls.java#L607). On the other hand, tags are implemented as [InheritableThreadLocal](https://github.com/apache/spark/blob/4fdb4abb260bd6df09c6239cea3e962c1b709381/sql/connect/common/src/main/scala/org/apache/spark/sql/connect/client/SparkConnectClient.scala#L285). So, if the futures q1 and q4, or q2 and q3 are parent and child, tags should be inherited, which causes the flaky test failure. You can easily reproduce the issue by inserting a sleep into the problematic test like as follows (don't forget to replace `ignore` with `test`). ``` // TODO(SPARK-48139): Re-enable `SparkSessionE2ESuite.interrupt tag` - ignore("interrupt tag") { + test("interrupt tag") { val session = spark import session.implicits._ -204,6 +204,7 class SparkSessionE2ESuite extends ConnectFunSuite with RemoteSparkSession { spark.clearTags() // clear for the case of thread reuse by another Future } }(executionContext) + Thread.sleep(1000) val q4 = Future { assert(spark.getTags() == Set()) spark.addTag("one") ``` And then, run the test. ``` $ build/sbt 'connect-client-jvm/testOnly org.apache.spark.sql.connect.SparkSessionE2ESuite -- -z "interrupt tag"' ``` ### Why are the changes needed? For test stability. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Ran the problematic test with inserting sleep like mentioned above and it passed. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#52476 from sarutak/fix-thread-pool-issue-4.0. Authored-by: Kousuke Saruta <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
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?
This PR backports #52417 to
branch-4.0.This PR aims to fix one of the issues which block SPARK-48139.
In the problematic test
interrupt taginSparkSessionE2ESuite, four futures run on threads inForkJoinPooland try to interrupt through tags.A thread in a
ForkJoinPoolcan create a spare thread and make it available in the pool so any of threads can be parent and child. It can happen when a thread performs a blocking operation. One example isArrayBlockingQueue.takeand it is called in a method provided by gRPC.On the other hand, tags are implemented as InheritableThreadLocal.
So, if the futures q1 and q4, or q2 and q3 are parent and child, tags should be inherited, which causes the flaky test failure.
You can easily reproduce the issue by inserting a sleep into the problematic test like as follows (don't forget to replace
ignorewithtest).And then, run the test.
Why are the changes needed?
For test stability.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Ran the problematic test with inserting sleep like mentioned above and it passed.
Was this patch authored or co-authored using generative AI tooling?
No.