Skip to content

[SPARK-52381][CORE] JsonProtocol: Only accept subclasses of SparkListenerEvent #51061

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pjfanning
Copy link
Contributor

What changes were proposed in this pull request?

JsonProtocol tidy up. Only parse JSON relating to Spark events.
https://issues.apache.org/jira/browse/SPARK-52381

Why are the changes needed?

Tidier code and https://lists.apache.org/thread/9zwkdo85wcdfppgqvbhjly8wdgf595yp

Does this PR introduce any user-facing change?

No

How was this patch tested?

Unit test

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

No

@github-actions github-actions bot added the CORE label Jun 2, 2025
case other => mapper.readValue(json.toString, Utils.classForName(other))
.asInstanceOf[SparkListenerEvent]
case other =>
if (other.startsWith("org.apache.spark")) {
Copy link
Member

@pan3793 pan3793 Jun 2, 2025

Choose a reason for hiding this comment

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

is it possible to have an allowList ? downstream projects may have custom events, i.e. Apache Kyuubi has custom events under org.apache.kyuubi package

https://github.com/apache/kyuubi/blob/v1.10.2/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/events/EngineEvent.scala

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @pan3793, I've removed the check for the package name and now just check if the class is a subclass of SparkListenerEvent.

@pjfanning pjfanning changed the title [SPARK-52381][Core] JsonProtocol: Only accept Spark classes [SPARK-52381][Core] JsonProtocol: Only accept subclasses of SparkEventListener Jun 2, 2025
@pjfanning pjfanning changed the title [SPARK-52381][Core] JsonProtocol: Only accept subclasses of SparkEventListener [SPARK-52381][Core] JsonProtocol: Only accept subclasses of SparkListenerEvent Jun 2, 2025
@pan3793
Copy link
Member

pan3793 commented Jun 3, 2025

Test failure looks related, otherwise LGTM

[info] - SPARK-47148: AQE should avoid to submit shuffle job on cancellation *** FAILED *** (6 seconds, 95 milliseconds)
[info]   scala.`package`.Seq.apply[org.apache.spark.SparkException](error).++[Throwable](scala.Option.apply[Throwable](error.getCause())).++[Throwable](scala.Predef.wrapRefArray[Throwable](error.getSuppressed())).exists(((e: Throwable) => e.getMessage().!=(null).&&(e.getMessage().contains("coalesce test error")))) was false (AdaptiveQueryExecSuite.scala:938)

cc @LuciferYang

@mridulm
Copy link
Contributor

mridulm commented Jun 3, 2025

It looks like the discussion thread is not accessible ?
I am trying to understand the rationale for the change - is it to prevent a class cast exception ?

@github-actions github-actions bot added the SQL label Jun 5, 2025
@@ -935,8 +935,9 @@ class AdaptiveQueryExecSuite
val error = intercept[SparkException] {
joined.collect()
}
assert((Seq(error) ++ Option(error.getCause) ++ error.getSuppressed()).exists(
e => e.getMessage() != null && e.getMessage().contains("coalesce test error")))
val exceptionMessages = (Seq(error) ++ Option(error.getCause) ++ error.getSuppressed())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change necessary? The issue "SPARK-47148: AQE should avoid submitting a shuffle job upon cancellation" is associated with a flaky test.

Copy link
Contributor Author

@pjfanning pjfanning Jun 6, 2025

Choose a reason for hiding this comment

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

I can undo this. The test failed during one run for me and I made this change to try to debug it.
This change makes it easier for Scalatest to infer a test failure message because the collection being asserted on is a Seq[String] instead of Seq[Exception].

Uninformative message from recent test failure:
#51061 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LuciferYang do you still want me to revert this? It is a test and the existing code made it quite hard to debug it while the newer code makes it easier.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this change holds significance, I recommend submitting it in a standalone pr as it's not relevant to the theme of the current pr, correct?

@pjfanning
Copy link
Contributor Author

Test failure looks related, otherwise LGTM

[info] - SPARK-47148: AQE should avoid to submit shuffle job on cancellation *** FAILED *** (6 seconds, 95 milliseconds)
[info]   scala.`package`.Seq.apply[org.apache.spark.SparkException](error).++[Throwable](scala.Option.apply[Throwable](error.getCause())).++[Throwable](scala.Predef.wrapRefArray[Throwable](error.getSuppressed())).exists(((e: Throwable) => e.getMessage().!=(null).&&(e.getMessage().contains("coalesce test error")))) was false (AdaptiveQueryExecSuite.scala:938)

cc @LuciferYang

@pan3793 that test seems to have passed on the last build for this PR. I have modified the test in this PR to make the assertion easier for ScalaTest to infer informative failure messages for - but the slow sql tests passed so the change didn't help.

@LuciferYang
Copy link
Contributor

It looks like the discussion thread is not accessible ? I am trying to understand the rationale for the change - is it to prevent a class cast exception ?

Friendly ping @mridulm, What do you think about this PR?

@mridulm
Copy link
Contributor

mridulm commented Jun 6, 2025

IMO this is not a security issue - as discussed in the thread, users need too much access to begin with in order to leverage the "exploit" (pls do let me know if I am missing some nuance here where this can be a problem !).
Having said that, the change itself looks fine and does not introduce any behavior change.

I am not strongly in favor of, or against the change @LuciferYang - will let you drive it.

…t subclasses

extra check

scalastyle

Update JsonProtocolSuite.scala
@github-actions github-actions bot removed the SQL label Jun 26, 2025
@LuciferYang LuciferYang changed the title [SPARK-52381][Core] JsonProtocol: Only accept subclasses of SparkListenerEvent [SPARK-52381][CORE] JsonProtocol: Only accept subclasses of SparkListenerEvent Jun 26, 2025
Copy link
Contributor

@LuciferYang LuciferYang left a comment

Choose a reason for hiding this comment

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

+1, LGTM

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.

4 participants