Skip to content

Fix stale ExecutorClassLoader leak and local JAR staging in portable Spark runner - #40270

Merged
Amar3tto merged 1 commit into
apache:masterfrom
Abacn:fix-spark-staging
Sep 25, 2026
Merged

Amar3tto merged 1 commit into
apache:masterfrom
Abacn:fix-spark-staging

Conversation

@Abacn

@Abacn Abacn commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fix #40256

  • Set an explicit contextClassLoader on JobInvoker, SparkPipelineRunner, and SparkContextFactory threads so subsequent jobs do not inherit a closed Spark ExecutorClassLoader leaked onto shared grpc-default-executor threads.

  • Skip SparkConf.setJars in SparkContextFactory when running on a local Spark master (local, local[N], local[*], local[N,M]), avoiding copying classpath JARs into temporary per-context userFiles directories that are deleted when the SparkContext stops.

  • Broaden SparkCommonPipelineOptions.isLocalSparkMaster to match all local master variants (local[*], local[N,M]) and add unit test coverage in SparkPipelineOptionsTest.

Please add a meaningful description for your change here


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@Abacn

Abacn commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

The race and leak has always been there (#30512 (comment) mitigated in #32723 but never fixed root cause), but only get exposed in Structured Streaming because it uses ServiceLoader.load() vs ClassLoader.loadClass() in RDD/DStream.

…Spark runner

- Set an explicit contextClassLoader on `JobInvoker`, `SparkPipelineRunner`, and `SparkContextFactory` threads so subsequent jobs do not inherit a closed Spark `ExecutorClassLoader` leaked onto shared `grpc-default-executor` threads.

- Skip `SparkConf.setJars` in `SparkContextFactory` when running on a local Spark master (`local`, `local[N]`, `local[*]`, `local[N,M]`), avoiding copying classpath JARs into temporary per-context `userFiles` directories that are deleted when the `SparkContext` stops.

- Broaden `SparkCommonPipelineOptions.isLocalSparkMaster` to match all local master variants (`local[*]`, `local[N,M]`) and add unit test coverage in `SparkPipelineOptionsTest`.
@Abacn
Abacn marked this pull request as ready for review September 24, 2026 21:10
@Abacn

Abacn commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

R: @Amar3tto @aIbrahiim

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@Amar3tto
Amar3tto merged commit 13a3083 into apache:master Sep 25, 2026
20 checks passed
@Abacn Abacn mentioned this pull request Sep 28, 2026
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.

The PostCommit Java PVR Spark4 StructuredStreaming job is flaky

2 participants