-
Notifications
You must be signed in to change notification settings - Fork 2.6k
On SIGTERM default to a non-zero exit code #21300
Changes from all commits
db24947
7853aab
73a39ae
ba3e53b
eb976a4
371cd23
95051d8
75dea6c
fa5de42
2e13cad
17ae6ea
b0bc41c
d89a547
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
#include "perfcounters.h" | ||
#include "eventtrace.h" | ||
#include "virtualcallstub.h" | ||
#include "utilcode.h" | ||
|
||
#if defined(_TARGET_X86_) | ||
#define USE_CURRENT_CONTEXT_IN_FILTER | ||
|
@@ -203,10 +204,23 @@ static inline void UpdatePerformanceMetrics(CrawlFrame *pcfThisFrame, BOOL bIsRe | |
ETW::ExceptionLog::ExceptionThrown(pcfThisFrame, bIsRethrownException, bIsNewException); | ||
} | ||
|
||
void ShutdownEEAndExitProcess() | ||
#ifdef FEATURE_PAL | ||
static LONG volatile g_termination_triggered = 0; | ||
|
||
void HandleTerminationRequest(int terminationExitCode) | ||
{ | ||
ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete); | ||
// We set a non-zero exit code to indicate the process didn't terminate cleanly. | ||
// This value can be changed by the user by setting Environment.ExitCode in the | ||
// ProcessExit event. We only start termination on the first SIGTERM signal | ||
// to ensure we don't overwrite an exit code already set in ProcessExit. | ||
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. What happens if the SIGTERM causes an int-returning Program.Main to exit gracefully and return a non-zero exit code? I'm aware of dotnet/aspnetcore#6526 which tracks using Environment.ExitCode in the ProcessExit event to set the process exit code to zero when the ASP.NET host exits gracefully. I'm more concerned about apps that return custom exit codes from Program.Main. Today this works as long as you avoid 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.
The program observing the exit code will assume the application didn't exit gracefully.
The ProcessExit handler must be aware of those. It can behave different based on the Environment.ExitCode value. |
||
if (InterlockedCompareExchange(&g_termination_triggered, 1, 0) == 0) | ||
{ | ||
SetLatchedExitCode(terminationExitCode); | ||
|
||
ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete); | ||
} | ||
} | ||
#endif | ||
|
||
void InitializeExceptionHandling() | ||
{ | ||
|
@@ -229,7 +243,7 @@ void InitializeExceptionHandling() | |
PAL_SetGetGcMarkerExceptionCode(GetGcMarkerExceptionCode); | ||
|
||
// Register handler for termination requests (e.g. SIGTERM) | ||
PAL_SetTerminationRequestHandler(ShutdownEEAndExitProcess); | ||
PAL_SetTerminationRequestHandler(HandleTerminationRequest); | ||
#endif // FEATURE_PAL | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.