It looks like the ThreadAbortException is not always re-thrown by the runtime. See below for a sample program that reproduces the issue, causing an infinite thread loop.
I have reproduced this on two 64-bit systems running .NET Framework 4.6.1 and 4.7.1 respectively.
I can not reproduce on .NET Framework 4.5.2.
The issue goes away if forcing usage of the legacy jit compiler with the following config:
<runtime>
<useLegacyJit enabled="1" />
</runtime>
I have reproduced with the following program built using Visual Studio Enterprise 2017, Version 15.5.2, targeting .NET Framework 4, Any CPU, Release build:
using System;
using System.Threading;
namespace ConsoleApp {
class Program {
static bool started = false;
static void Main(string[] args) {
// Start thread
var thread = new Thread(ThreadLoop);
thread.Start();
while (!started);
// Abort thread
Console.WriteLine($"Aborting thread");
thread.Abort();
}
private static void ThreadLoop() {
Console.WriteLine($"Thread started");
int cnt = 0;
while (true) {
try {
if (!started) {
Console.WriteLine($"Thread loop");
started = true;
}
}
catch (ThreadAbortException) {
Console.WriteLine($"ThreadAbortException #{cnt++}");
}
}
}
}
}
The output when reproducing:
Thread started
Thread loop
Aborting thread
ThreadAbortException #0
ThreadAbortException dotnet/coreclr#1
ThreadAbortException dotnet/coreclr#2
ThreadAbortException dotnet/coreclr#3
ThreadAbortException dotnet/coreclr#4
ThreadAbortException dotnet/coreclr#5
ThreadAbortException dotnet/coreclr#6
ThreadAbortException dotnet/coreclr#7
ThreadAbortException dotnet/coreclr#8
ThreadAbortException dotnet/coreclr#9
ThreadAbortException dotnet/coreclr#10
ThreadAbortException dotnet/coreclr#11
ThreadAbortException dotnet/coreclr#12
ThreadAbortException dotnet/coreclr#13
ThreadAbortException dotnet/coreclr#14
ThreadAbortException dotnet/coreclr#15
ThreadAbortException dotnet/coreclr#16
ThreadAbortException dotnet/coreclr#17
ThreadAbortException dotnet/coreclr#18
ThreadAbortException dotnet/coreclr#19
(continuing forever)
I am aware of issue https://github.com/dotnet/coreclr/issues/3155, but it does not sound like the exact same issue.
Any thoughts on this?
It looks like the ThreadAbortException is not always re-thrown by the runtime. See below for a sample program that reproduces the issue, causing an infinite thread loop.
I have reproduced this on two 64-bit systems running .NET Framework 4.6.1 and 4.7.1 respectively.
I can not reproduce on .NET Framework 4.5.2.
The issue goes away if forcing usage of the legacy jit compiler with the following config:
I have reproduced with the following program built using Visual Studio Enterprise 2017, Version 15.5.2, targeting .NET Framework 4, Any CPU, Release build:
The output when reproducing:
I am aware of issue https://github.com/dotnet/coreclr/issues/3155, but it does not sound like the exact same issue.
Any thoughts on this?