Bug 2845 - GC + Thread.Abort() + Thread.Join() = Hang
Summary: GC + Thread.Abort() + Thread.Join() = Hang
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-11 12:46 UTC by Jonathan Pryor
Modified: 2017-07-11 22:05 UTC (History)
5 users (show)

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


Attachments
abort.cs (1.23 KB, application/octet-stream)
2012-01-11 12:46 UTC, Jonathan Pryor
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jonathan Pryor 2012-01-11 12:46:47 UTC
Created attachment 1167 [details]
abort.cs

The attached test case is a distillation of #1394 Attachment #881 [details], sans the Mono for Android and Sockets dependencies.

It amounts to creating lots of threads, calling Thread.Abort() on them, then Thread.Join() on them.

Build + run the test on mono 2.10 or master/d901061, and the application hangs:

  $ mono abort.ex
  ...
  Joining thread: 6
  <HANG>

Note: it may take awhile, but it consistently hangs within 5 seconds of execution on my MBP (OSX).

As an added "wrinkle", on Mono 2.10.8 (OSX), if you get really unlucky (or wait around long enough), the runtime will abort. (Though now that I mention this, it doesn't happen anymore. Maybe the abort was when sockets were being used as well?)

One final "that's interesting": if you remove the array allocation in abort.cs:57, then execution does NOT hang (at least not within 5s). I have no idea why creating an unused 1024k array would prompt the hang, but there you go.
Comment 1 Zoltan Varga 2012-01-23 03:37:20 UTC
-> runtime.
Comment 2 Iain 2012-03-06 05:55:44 UTC
Looks like the GC gets into an infinite loop, at least with my original sample anyway (have not tried Jon's code on OSX I must confess)...

Anyway, I thought I'd post a quick update as I had noticed that if you run my original sample (attachment #881 [details] on bug #1394) using MFA with the following logging:

adb shell setprop debug.mono.env MONO_GC_DEBUG=5

...then sit back and watch the fun!  

Hope that helps track it down!

Cheers
Iain

--- snip logcat output ---

I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4173264 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2136 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1225 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 62 in 305 usecs
I/mono-gc ( 3862): Old generation scan: 91 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4174608 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2197 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1226 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 61 in 305 usecs
I/mono-gc ( 3862): Old generation scan: 61 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4176472 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2288 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1227 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 61 in 427 usecs
I/mono-gc ( 3862): Old generation scan: 213 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 183 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4176696 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2746 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1228 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 63 in 305 usecs
I/mono-gc ( 3862): Old generation scan: 61 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4173752 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2044 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1229 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 54 in 244 usecs
I/mono-gc ( 3862): Old generation scan: 61 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4176152 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2380 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1230 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 55 in 396 usecs
I/mono-gc ( 3862): Old generation scan: 183 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 152 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4177016 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2746 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1231 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 61 in 274 usecs
I/mono-gc ( 3862): Old generation scan: 61 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4175752 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2258 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1232 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 56 in 274 usecs
I/mono-gc ( 3862): Old generation scan: 91 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4177064 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2075 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1233 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 58 in 274 usecs
I/mono-gc ( 3862): Old generation scan: 61 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 30 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4175792 bytes available
I/mono-gc ( 3862): Heap size: 14680064, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 2197 usec, max: 56427)
I/mono-gc ( 3862): Start nursery collection 1234 0x4a800000-0x4ac00000, size: 4194304
I/mono-gc ( 3862): Scanning pinned roots (15922 bytes, 78/7 entries)
I/mono-gc ( 3862): Finding pinned pointers: 54 in 396 usecs
I/mono-gc ( 3862): Old generation scan: 183 usecs
I/mono-gc ( 3862): nursery generation done
I/mono-gc ( 3862): Finalize queue handling scan for nursery generation: 213 usecs 2 ephemeron roundss
I/mono-gc ( 3862): Fragment creation: 30 usecs, 4177144 bytes available
I/mono-gc ( 3862): Heap size: 15204352, LOS size: 0
I/mono-gc ( 3862): restarted 10 thread(s) (pause time: 3997 usec, max: 56427)

--- snip ---
Comment 3 Rodrigo Kumpera 2013-09-09 12:23:20 UTC
This doesn't happen with mono 3.X as we switch to the new suspend machinery. We need to rollout this to ARM.
Comment 4 Rodrigo Kumpera 2017-07-11 22:05:22 UTC
Fixed a while ago.