Bug 38794 - Segmentation fault Console.ReadLine while exiting the application
Summary: Segmentation fault Console.ReadLine while exiting the application
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Aleksey Kliger
Depends on:
Reported: 2016-02-16 13:25 UTC by Wouter Post
Modified: 2017-10-06 20:32 UTC (History)
5 users (show)

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

The C# code to reproduce the error (1.21 KB, text/plain)
2016-02-16 13:25 UTC, Wouter Post
Bash loop script (214 bytes, text/plain)
2016-02-16 13:28 UTC, Wouter Post
gdb log from core dump (3.90 KB, text/plain)
2016-02-22 14:42 UTC, Alexander Köplinger [MSFT]

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 Wouter Post 2016-02-16 13:25:49 UTC
Created attachment 15054 [details]
The C# code to reproduce the error


I've come across this bug in mono 2.11.4, 3.2.1 and 3.12.1.
Whenever Console.ReadLine() is executed in a background thread while the application is exiting, segmentation faults can occur.

I've made a bash loop script to try it out multiple times since the segfault doesn't seem to occur every time.
Sometimes it takes 500 attempts and sometimes only 5.

The code can be compiled with mcs or in visual studio with .net, both generate the error.
Comment 1 Wouter Post 2016-02-16 13:28:23 UTC
Created attachment 15055 [details]
Bash loop script

Added bash loop script for testing.
Comment 2 Aleksey Kliger 2016-02-19 17:19:03 UTC
No longer reproducible with 4.2 or HEAD on Debian x64 or OSX after ~1500 iterations.
Comment 3 Alexander Köplinger [MSFT] 2016-02-22 14:41:42 UTC
I can reproduce the segfault on Mono 3.12, Mono 4.0 and Mono 4.2 using the Mono Docker images and with 4.2 on the Ubuntu 14.04 x64 host VM (though it took about ~2500 iterations there).

I was also able to repro it using master/f558ee9 too so the bug is definitely still there.

I've attached a stack trace from the core dump of the master build and assigning to Aleksey since you already took a look earlier, please feel to reassign to someone more appropriate :)
Comment 4 Alexander Köplinger [MSFT] 2016-02-22 14:42:28 UTC
Created attachment 15123 [details]
gdb log from core dump
Comment 5 Ludovic Henry 2017-09-06 15:47:11 UTC
We have changed how threads are stopped so this might be fixed with latest version of Mono. Can you still reproduce with Mono (2017-06/6425f06) or later? Thank you
Comment 6 Ludovic Henry 2017-10-06 20:32:32 UTC
Please reopen if you can still reproduce. Thank you