-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-48547][DEPLOY] Add opt-in flag to have SparkSubmit automatically call System.exit after user code main method exits #52091
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1022,11 +1022,19 @@ private[spark] class SparkSubmit extends Logging { | |
| e | ||
| } | ||
|
|
||
| var exitCode: Int = 1 | ||
| try { | ||
| app.start(childArgs.toArray, sparkConf) | ||
| exitCode = 0 | ||
| } catch { | ||
| case t: Throwable => | ||
| throw findCause(t) | ||
| val cause = findCause(t) | ||
| cause match { | ||
| case e: SparkUserAppException => | ||
| exitCode = e.exitCode | ||
| case _ => | ||
| } | ||
| throw cause | ||
| } finally { | ||
| if (args.master.startsWith("k8s") && !isShell(args.primaryResource) && | ||
| !isSqlShell(args.mainClass) && !isThriftServer(args.mainClass) && | ||
|
|
@@ -1037,6 +1045,12 @@ private[spark] class SparkSubmit extends Logging { | |
| case e: Throwable => logError("Failed to close SparkContext", e) | ||
| } | ||
| } | ||
| if (sparkConf.get(SUBMIT_CALL_SYSTEM_EXIT_ON_MAIN_EXIT)) { | ||
| logInfo( | ||
| log"Calling System.exit() with exit code ${MDC(LogKeys.EXIT_CODE, exitCode)} " + | ||
| log"because main ${MDC(LogKeys.CONFIG, SUBMIT_CALL_SYSTEM_EXIT_ON_MAIN_EXIT.key)}=true") | ||
| exitFn(exitCode) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In one of our internal implementations, we initiated a timer that permitted certain slow non-demon threads to complete their tasks, such as updating external metrics and reporting states. Upon the timer's expiration, the system logs a message, records thread dumps of all active threads (this can be used for triaging the cause of the condition), and subsequently exits. Can you extend this patch to do these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like this: `..... def createAndStartShutdownThread(timeToWaitInSeconds: Long, exitCode: Int): Unit = { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @itskals I think it's more appropriate to implement this in a shutdown hook. You actually want a graceful shutdown mechanism that's not coupled to either daemon or non-daemon threads. If users want to do some cleanup work or graceful shutdown logic before the JVM terminates, they need to register a shutdown hook rather than creating non-daemon threads. BTW, you can use three backticks to quote the code block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the usage of non-demon threads is not desirable, it's hard to enforce in actual application development.
|
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
mainin this log line feels out of placeThere 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.
thank you for checking, updated.