Bug 54359 - SIGSEGV on Thread creation/start
Summary: SIGSEGV on Thread creation/start
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: Mono runtime / AOT compiler ()
Version: XI 10.4 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: 15.2
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2017-03-31 22:11 UTC by Troy O'Neal
Modified: 2017-04-26 02:11 UTC (History)
3 users (show)

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


Attachments
test case (10.28 KB, application/zip)
2017-04-01 22:40 UTC, Alex Soto [MSFT]
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 Developer Community or GitHub 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 NOT_REPRODUCIBLE

Description Troy O'Neal 2017-03-31 22:11:58 UTC
I'll note that my Xamarin Ios version is "10.6.0.9" (didn't find it in the selectable list).  Also wasn't sure whether this was a "Mono runtime" or "XI runtime" issue.  Feel free to recategorize.  Visual Studio Community 2015.  Running on "iPhone 7 Plus iOS 10.3" Simulator over a remote ssh connection, using rdp to view the device screen.

Anyway, the bug seems to be happening during fairly basic thread creation/joining/deletion operations. Although I was having problems in a much more complex application, I reduced the problem and came up with the following test case, which quickly crashes with a SIGSEGV:

public class ReproduceThreadingIssue
    {
        public void reproduce()
        {
            int i = 0;
            while (true)

            {
                Thread t = new Thread(threadLoop);
                t.Start();
                t.Join();
                t = null;
                Console.WriteLine("Looping " + (i++));
            }
        }

        public void threadLoop()
        {

        }
    }

I call the reproduce() function right from the ViewController.ViewDidLoad() for testing purposes.  The loop works for a few times and then the stack trace:

Native stacktrace:

2017-03-31 14:02:15.785 GLV_ios[64636:1184523] critical: 	0   GLV_ios                             0x000000010e5825ed mono_handle_native_sigsegv + 253
2017-03-31 14:02:15.785 GLV_ios[64636:1184523] critical: 	1   GLV_ios                             0x000000010e58e266 mono_sigsegv_signal_handler + 294
2017-03-31 14:02:15.786 GLV_ios[64636:1184523] critical: 	2   libsystem_platform.dylib            0x000000011b995b3a _sigtramp + 26
2017-03-31 14:02:15.786 GLV_ios[64636:1184523] critical: 	3   GLV_ios                             0x000000010e57f470 mono_walk_stack_with_state + 0
2017-03-31 14:02:15.786 GLV_ios[64636:1184523] critical: 	4   GLV_ios                             0x000000010e63b891 mono_runtime_delegate_try_invoke + 49
2017-03-31 14:02:15.787 GLV_ios[64636:1184523] critical: 	5   GLV_ios                             0x000000010e68137a start_wrapper + 538
2017-03-31 14:02:15.787 GLV_ios[64636:1184523] critical: 	6   GLV_ios                             0x000000010e6ea282 inner_start_thread + 354
2017-03-31 14:02:15.787 GLV_ios[64636:1184523] critical: 	7   libsystem_pthread.dylib             0x000000011b9a79af _pthread_body + 180
2017-03-31 14:02:15.788 GLV_ios[64636:1184523] critical: 	8   libsystem_pthread.dylib             0x000000011b9a78fb _pthread_body + 0
2017-03-31 14:02:15.788 GLV_ios[64636:1184523] critical: 	9   libsystem_pthread.dylib             0x000000011b9a7101 thread_start + 13
2017-03-31 14:02:15.788 GLV_ios[64636:1184523] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

is thrown.
I ran this same test code on Windows just to be sure, and it works fine on Windows.

Let me know what to do next or any workarounds.  Thanks.
Comment 1 Alex Soto [MSFT] 2017-04-01 22:40:31 UTC
Created attachment 21141 [details]
test case


Repro case

Thread started:  #733
Thread finished:  #733
2017-04-01 16:30:33.200 bug54359[17969:4051311] Looping 5190
Thread started:  #734
2017-04-01 16:30:33.203 bug54359[17969:4056802] critical: Stacktrace:

2017-04-01 16:30:33.203 bug54359[17969:4056802] critical: 
Native stacktrace:

2017-04-01 16:30:33.214 bug54359[17969:4056802] critical: 	0   bug54359                            0x0000000106bbbd9d mono_handle_native_sigsegv + 253
2017-04-01 16:30:33.214 bug54359[17969:4056802] critical: 	1   bug54359                            0x0000000106bc8ad6 mono_sigsegv_signal_handler + 294
2017-04-01 16:30:33.214 bug54359[17969:4056802] critical: 	2   libsystem_platform.dylib            0x00000001129b6b3a _sigtramp + 26
2017-04-01 16:30:33.214 bug54359[17969:4056802] critical: 	3   bug54359                            0x0000000106bb87c0 mono_walk_stack_with_state + 0
2017-04-01 16:30:33.215 bug54359[17969:4056802] critical: 	4   bug54359                            0x0000000106c7e9e1 mono_runtime_delegate_try_invoke + 49
2017-04-01 16:30:33.215 bug54359[17969:4056802] critical: 	5   bug54359                            0x0000000106cc887a start_wrapper + 538
2017-04-01 16:30:33.215 bug54359[17969:4056802] critical: 	6   bug54359                            0x0000000106d34c42 inner_start_thread + 354
2017-04-01 16:30:33.215 bug54359[17969:4056802] critical: 	7   libsystem_pthread.dylib             0x00000001129c89af _pthread_body + 180
2017-04-01 16:30:33.216 bug54359[17969:4056802] critical: 	8   libsystem_pthread.dylib             0x00000001129c88fb _pthread_body + 0
2017-04-01 16:30:33.216 bug54359[17969:4056802] critical: 	9   libsystem_pthread.dylib             0x00000001129c8101 thread_start + 13
2017-04-01 16:30:33.216 bug54359[17969:4056802] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 2 Alex Soto [MSFT] 2017-04-01 22:44:06 UTC
I can confirm the above scenario using this test case using current stable tools

=== Xamarin Studio Enterprise ===

Version 6.2.1 (build 3)
Installation UUID: 48af9690-0e4c-4b21-b82d-5c9cce64d17e
Runtime:
	Mono 4.8.0 (mono-4.8.0-branch/8f6d0f6) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000520

=== Apple Developer Tools ===

Xcode 8.3 (12169)
Build 8E162

=== Xamarin.iOS ===

Version: 10.6.0.10 (Visual Studio Enterprise)
Hash: e66c6f19
Branch: xcode8.3
Build date: 2017-03-28 00:48:33-0400

=== Build Information ===

Release ID: 602010003
Git revision: 5217903c99e9d9c5d3caa2498fd66d607debac29
Build date: 2017-03-23 12:36:46-04
Xamarin addins: 2c96d252b353fce2e8b8fd20884eee70c16c7f32
Build lane: monodevelop-lion-cycle9

=== Operating System ===

Mac OS X 10.12.4
Darwin iAlexRet.lan 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 3 Alex Soto [MSFT] 2017-04-03 13:17:21 UTC
I can confirm this no longer happens on dev15.1 branch 

=== Xamarin Studio Enterprise ===

Version 6.3 (build 858)
Installation UUID: 8b628af4-2681-40da-b012-6efe60d58328
Runtime:
	Mono 4.8.0 (mono-4.8.0-branch/9d74414) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000524

=== NuGet ===

Version: 3.5.0.0

=== Xamarin.Profiler ===

Version: 1.4.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3 (12169)
Build 8E162

=== Xamarin.Android ===

Version: 7.2.0.7 (Visual Studio Enterprise)
Android SDK: /Users/alex/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		6.0 (API level 23)

SDK Tools Version: 25.1.2
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.2.0
Hash: 62c17e6
Branch: d15-1
Build date: Mon, 20 Mar 2017 02:36:23 GMT

=== Xamarin.iOS ===

Version: 10.8.0.33 (Visual Studio Enterprise)
Hash: 06b241f
Branch: d15-1
Build date: 2017-03-24 11:21:18-0400

=== Xamarin.Mac ===

Version: 3.2.0.33 (Visual Studio Enterprise)

=== Build Information ===

Release ID: 603000858
Git revision: 9b45838d2486d0c26567c7ebf94487e4daedafd6
Build date: 2017-03-23 12:40:43-04
Xamarin addins: e66d8957d0ff8dd7f727a3cc75de56ca235b5f60
Build lane: monodevelop-lion-d15-1

=== Operating System ===

Mac OS X 10.12.4
Darwin iAlexRet.lan 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 4 Alex Soto [MSFT] 2017-04-03 13:18:00 UTC
Dev15.1 is currently on our beta channel
Comment 5 Troy O'Neal 2017-04-26 00:45:54 UTC
Coming back to this bug.  I just upgraded to 15.1 from the stable channel, rebuilt, and ran the simple test case again, and immediately it crashed, exactly as before.  I'm downloading 15.2 from the beta channel now and going to try it on that.  

Suggestions to get this working or to aid reproduction on your end?
Comment 6 Alex Soto [MSFT] 2017-04-26 01:28:25 UTC
Interesting, I can confirm this is happening in 15.1 I wonder what happened because it wasn't I am moving this to 15.2 branch in the meantime, let me check if it also happens on 15.2.
Comment 7 Alex Soto [MSFT] 2017-04-26 01:42:30 UTC
Ok, I can't reproduce this with xamarin-macios/d15-2 @ 2f87f21c6000f9487845b4ade3448a65fc252f6b

@Troy if you use 15.2 you should be all good you can follow our releases here https://releases.xamarin.com

Sorry for the inconvenience with 15.1 not sure what happened but at this stage 15.2 should do.

Cheers.

System info:

=== Visual Studio for Mac Preview ===

Version Preview 9 (7.0 build 2956)
Installation UUID: 1899e9c0-871d-400c-9fdf-d07922303241
Runtime:
	Mono 5.0.0.60 (2017-02/12f8eba) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500000060

=== NuGet ===

Version: 4.0.0.2323

=== .NET Core ===

Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.4.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3 (12169)
Build 8E162

=== Xamarin.iOS ===

Version: 10.10.0.10 (Visual Studio Enterprise)
Hash: 2f87f21c
Branch: d15-2
Build date: 2017-04-18 12:17:51-0500

=== Xamarin.Android ===

Version: 7.2.0.7 (Visual Studio Enterprise)
Android SDK: /Users/alex/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)
		7.1    (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.Mac ===

Version: 3.4.0.10 (Visual Studio Enterprise)

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Build Information ===

Release ID: 700002956
Git revision: cf8f91e9858e8b712cecf206324634c8065e8c1c
Build date: 2017-04-24 13:51:12-04
Xamarin addins: 703c0efbdfbb51c78758486ccd852ff825226660
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.4
Darwin 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 8 Troy O'Neal 2017-04-26 02:11:02 UTC
Sounds good.  Thanks @Alex for prompt help.  I can't use 15.2 right now because I'm using this managed mac server that isn't compatible with 15.2 until it's stable.  I'll let you know if it works on there when 15.2 is stable.

Over the last couple hours I switched my backend thread API to use NSThread instead of System.Threading.Thread and the problem went away.  So it seems like using NSThread is a good workaround for now.