Skip to content

Commit 9e1a746

Browse files
pavelsavarajkotas
andauthored
nested FailFast (#121306)
Co-authored-by: Jan Kotas <[email protected]>
1 parent 8dbf912 commit 9e1a746

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/coreclr/classlibnative/bcltype/system.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ static StackWalkAction FindFailFastCallerCallback(CrawlFrame* frame, VOID* data)
117117
return SWA_ABORT;
118118
}
119119

120+
static thread_local int8_t alreadyFailing = 0;
121+
120122
extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark, PCWSTR message, QCall::ObjectHandleOnStack exception, PCWSTR errorSource)
121123
{
122124
QCALL_CONTRACT;
@@ -143,7 +145,14 @@ extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark,
143145

144146
LPCWSTR argExceptionString = NULL;
145147
StackSString msg;
146-
if (exception.Get() != NULL)
148+
// Because Environment_FailFast should kill the process, any subsequent calls are likely nested call from managed while formatting the exception message or the stack trace.
149+
// Only collect exception string if this is the first attempt to fail fast on this thread.
150+
alreadyFailing++;
151+
if (alreadyFailing != 1)
152+
{
153+
argExceptionString = W("Environment.FailFast called recursively.");
154+
}
155+
else if (exception.Get() != NULL)
147156
{
148157
GetExceptionMessage(exception.Get(), msg);
149158
argExceptionString = msg.GetUnicode();

0 commit comments

Comments
 (0)