Skip to content

[SPARK-51660][CORE] Gracefully handle when MDC is not supported #50452

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
wants to merge 4 commits into from

Conversation

robreeves
Copy link
Contributor

@robreeves robreeves commented Mar 28, 2025

What changes were proposed in this pull request?

This improves the handling when MDC is not supported. The previous handling only works when one task runs on an executor. After this fix multiple tasks can run on an executor when MDC is not supported.

Why are the changes needed?

In #35141 it added handling to gracefully handle when MDC is not available. It catches NoSuchFieldError, which is thrown during MDC initialization. This will work for the first task. If a second task runs it will not throw a NoSuchFieldError. Instead it throws NoClassDefFoundError. Then the job will hang indefinitely. This improves the fix so it works for all tasks instead of just the first one.

Does this PR introduce any user-facing change?

Yes, it fixes a bug. It also changes a log message to include the exception for easier debugging.

How was this patch tested?

I tested it manually in spark-shell by manually throwing NoSuchFieldError. It logs this message and does not hang.

25/03/28 14:11:48 INFO Executor: MDC is not supported.
java.lang.NoSuchFieldError: this is a test
    at org.apache.spark.executor.Executor.liftedTree1$1(Executor.scala:118)
    at org.apache.spark.executor.Executor.mdcIsSupported$lzycompute(Executor.scala:114)
    at org.apache.spark.executor.Executor.mdcIsSupported(Executor.scala:113)
    at org.apache.spark.executor.Executor.org$apache$spark$executor$Executor$$setMDCForTask(Executor.scala:948)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:584)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the CORE label Mar 28, 2025
@robreeves robreeves marked this pull request as ready for review March 28, 2025 21:42
@robreeves
Copy link
Contributor Author

@dongjoon-hyun please take a look

Copy link
Contributor

@mridulm mridulm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good to me.
+CC @dongjoon-hyun as well.

@robreeves
Copy link
Contributor Author

@dongjoon-hyun gentle ping on this

@robreeves
Copy link
Contributor Author

@viirya can you take a look since you reviewed the original PR #35141?

@mridulm mridulm closed this in bc5ccad Apr 13, 2025
@mridulm
Copy link
Contributor

mridulm commented Apr 13, 2025

Merged to master.
Thanks for fixing this @robreeves !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants