From 61c1e08f0c66f57e385c718e2b555149a195ce7f Mon Sep 17 00:00:00 2001 From: Lobo2008 <842315999@qq.com> Date: Tue, 4 Aug 2026 11:19:55 +0800 Subject: [PATCH 1/2] [SPARK-58536] Fix getDefaultFinalStatus to return SUCCEEDED in cluster mode The docstring for getDefaultFinalStatus() says it should return SUCCEEDED in cluster mode 'to handle if the user calls System.exit from the application code', but the implementation returns FAILED. This causes applications that exit normally via System.exit(0) in cluster mode to report FAILED to YARN RM when the shutdown hook fires before finish(SUCCEEDED) is reached. Fix the implementation to match the documented behavior. --- .../scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala index 9c9f6f3bc313a..79b766eddf1b7 100644 --- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala +++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala @@ -351,7 +351,7 @@ private[spark] class ApplicationMaster( */ final def getDefaultFinalStatus(): FinalApplicationStatus = { if (isClusterMode) { - FinalApplicationStatus.FAILED + FinalApplicationStatus.SUCCEEDED } else { FinalApplicationStatus.UNDEFINED } From d2d054d37f47c4dd294d0b4289aa36e69239bcc2 Mon Sep 17 00:00:00 2001 From: Lobo2008 <842315999@qq.com> Date: Wed, 5 Aug 2026 09:54:07 +0800 Subject: [PATCH 2/2] [SPARK-58536] Fix stale docstring for getDefaultFinalStatus in cluster mode SPARK-38270 changed getDefaultFinalStatus() to return FAILED for cluster mode, but the docstring was not updated and still says SUCCEEDED. Fix the docstring to match the code. --- .../org/apache/spark/deploy/yarn/ApplicationMaster.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala index 79b766eddf1b7..dd7b73f4782cd 100644 --- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala +++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala @@ -345,9 +345,9 @@ private[spark] class ApplicationMaster( /** * Set the default final application status for client mode to UNDEFINED to handle - * if YARN HA restarts the application so that it properly retries. Set the final - * status to SUCCEEDED in cluster mode to handle if the user calls System.exit - * from the application code. + * if YARN HA restarts the application so that it properly retries. SPARK-38270 + * changed the default for cluster mode to FAILED to prevent the shutdown hook from + * reporting SUCCEEDED when the application exits with a non-zero exit code. */ final def getDefaultFinalStatus(): FinalApplicationStatus = { if (isClusterMode) {