Bug 43725 - Thread.Abort() is not delivered occasionally
Summary: Thread.Abort() is not delivered occasionally
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: master
Hardware: PC All
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
Depends on:
Reported: 2016-08-24 22:07 UTC by Andi McClure
Modified: 2016-08-29 06:22 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

modded monitor-abort test (1.17 KB, text/plain)
2016-08-24 22:07 UTC, Andi McClure

Description Andi McClure 2016-08-24 22:07:20 UTC
Created attachment 17205 [details]
modded monitor-abort test

One of our automated tests, monitor-abort.exe, fails with a hang about on about five percent of builds. It doesn't appear to correlate with any hardware platform. This has been happening for at least the last week and maybe longer.


If you look at the test, what it does is start about ten worker threads. All the worker threads plus the main thread line up on a Barrier, then all the worker threads block on a monitor the main thread is holding, then the main thread calls Abort followed by Join on all the threads. (There's actually a race where the worker threads are not guaranteed to be waiting on the monitor by the time the abort comes, but that's not relevant to the problem.)

If I run the test in a loop with some added Console.WriteLines, what it becomes clear is that one of the threads is getting Abort() called but is not aborting. The `catch (ThreadAbortException)` block is never entered. The monitor is not relevant to this, you can comment out Monitor.Enter and Monitor.Exit in ThreadFunc and replace it with a while(true); and you get the same problem.

To run in a loop, I run this

(export MD=`pwd`; cd mono/tests && (MONO_PATH=$MD/mcs/class/lib/net_4_x ../../runtime/mono-wrapper $MD/mcs/class/lib/build/mcs.exe -unsafe -debug -noconfig -nologo -nowarn:0162 -nowarn:0168 -nowarn:0219 -nowarn:0414 -nowarn:0618 -nowarn:0169 -nowarn:1690 -nowarn:0649 -nowarn:0612 -nowarn:3021 -nowarn:0197  -lib:$MD/mcs/class/lib/net_4_x -r:System.dll -r:System.Xml.dll -r:System.Core.dll -r:TestDriver.dll -r:Mono.Posix.dll -out:monitor-abort.exe monitor-abort.cs))

and then this

while (export MD=`pwd`; cd mono/tests && (MONO_ENV_OPTIONS="--gc=sgen" MONO_GC_DEBUG="" MONO_GC_PARAMS="" MONO_PATH=$MD/mcs/class/lib/net_4_x time ../../runtime/mono-wrapper monitor-abort.exe)); do :; done

The failure usually occurs pretty quickly.

My modded monitor-abort.cs with the WriteLines and while(true) is attached.

Note You need to log in before you can comment on or make changes to this bug.