Bug 15845 - Mono crashes with segmentation fault after a large number of threads finish
Summary: Mono crashes with segmentation fault after a large number of threads finish
Alias: None
Product: Runtime
Classification: Mono
Component: Debugger ()
Version: 3.2.x
Hardware: Other Other
: --- normal
Target Milestone: ---
Assignee: Zoltan Varga
Depends on:
Reported: 2013-10-31 08:49 UTC by June Rhodes
Modified: 2017-07-08 03:22 UTC (History)
6 users (show)

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

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:

Description June Rhodes 2013-10-31 08:49:46 UTC
Description of Problem:
Mono crashes after a large (~1000) threads have been started and ended.  It seems that installing "debuginfo" packages makes the problem go away?!? :(

Steps to reproduce the problem:
1. Use a version of Mono without debugging symbols
2. Start a large number of threads and allow them to finish before starting the next one
3. Watch Mono segmentation fault

Code to reproduce the problem:
1. Use a version of Mono without debugging symbols
2. Clone https://github.com/hach-que/Tychaia (player-movement branch)
3. Run Protobuild.exe to generate the solution file
4. Build
5. Run "Tychaia.exe" and click "Connect to local network"
6. Threads are constantly started and finish, so wait until a crash occurs

Reproducable on:
At least Linux

Actual Results:
Mono crashes with the stack trace (although no debugging symbols so it's not very useful).

Expected Results:
Mono should not crash.

How often does this happen? 
The crash can be reproduced, but the exact time and the number of threads that finish before a crash varies between each run.
Comment 1 June Rhodes 2013-10-31 08:50:59 UTC
For reference, prior to installing the debuginfo packages, I could only get to about thread 1000 before Mono would segmentation fault.  Now after running the same application under Mono with the debuginfo packages installed, I'm able to get to at least thread 9000 (and still counting).
Comment 2 June Rhodes 2013-10-31 08:51:29 UTC
Also exact version information:

Mono JIT compiler version 3.2.3 (tarball Thu Sep 26 16:24:36 UTC 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 3 Gery Vessere 2013-11-07 11:00:00 UTC
you might want to check with the fix made for this bug, your issue looks related to mine,

Comment 4 Rodrigo Kumpera 2013-12-06 15:00:46 UTC
Can you provide a test case that shows this problem?
Comment 5 Raphaël Boissel 2013-12-18 11:01:39 UTC
We are experiencing the same problem on a server using FreeBSD. One thread is trigger per task and after a certain time mono segfault. When no threading is performed we have no segfault. It seems to be around 10000 threads created (not simultaneously running of course).

I am trying to make a minimal test case for you.

I must admit that I have not had the time yet to take a look at the code or simply valgrind it.
Comment 6 Ludovic Henry 2017-07-08 03:22:02 UTC
Can you still reproduce with latest mono? If that's the case, feel free to reopen, and please provide a repro case. Thank you.