Bug 173 - Crash on app exit via mono assertion
Summary: Crash on app exit via mono assertion
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-08-04 03:53 UTC by rumination.xamarin
Modified: 2011-08-10 11:41 UTC (History)
3 users (show)

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

Test case (6.54 KB, application/zip)
2011-08-09 22:04 UTC, rumination.xamarin

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:

Description rumination.xamarin 2011-08-04 03:53:44 UTC
* Assertion at ../../../../mono/io-layer/handles.c:1143, condition `thr_ret == 0' not met


  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
  at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:26
  at Rumination.Crux.iOS.App.Main (string[]) [0x00077] in /Users/jrmorgan/Perforce/rumination/Crux/dev/Rumination.Crux.iOS/src/App/App.cs:140
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   Crux                                0x000d0de8 mono_handle_native_sigsegv + 343
	1   Crux                                0x0013afdd sigabrt_signal_handler + 116
	2   libSystem.B.dylib                   0x974a605b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libSystem.B.dylib                   0x975335a5 raise + 26
	5   libSystem.B.dylib                   0x975496e4 abort + 93
	6   Crux                                0x0027ee58 monoeg_g_logv + 197
	7   Crux                                0x0027eeba monoeg_assertion_message + 46
	8   Crux                                0x0024f82a _wapi_handle_unref + 784
	9   Crux                                0x0024d900 handle_cleanup + 168
	10  libSystem.B.dylib                   0x9745ec0a __cxa_finalize + 219
	11  libSystem.B.dylib                   0x9745eb14 exit + 33
	12  UIKit                               0x01cd8776 -[UIApplication _performMemoryWarning] + 0
	13  UIKit                               0x01cd907d -[UIApplication _handleApplicationSuspend:eventInfo:] + 2204
	14  UIKit                               0x01ce2039 -[UIApplication handleEvent:withNewEvent:] + 4127
	15  UIKit                               0x01cd9abf -[UIApplication sendEvent:] + 71
	16  UIKit                               0x01cdef2e _UIApplicationHandleEvent + 7576
	17  GraphicsServices                    0x0404f992 PurpleEventCallback + 1550
	18  CoreFoundation                      0x00ea2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
	19  CoreFoundation                      0x00e02cf7 __CFRunLoopDoSource1 + 215
	20  CoreFoundation                      0x00dfff83 __CFRunLoopRun + 979
	21  CoreFoundation                      0x00dff840 CFRunLoopRunSpecific + 208
	22  CoreFoundation                      0x00dff761 CFRunLoopRunInMode + 97
	23  GraphicsServices                    0x0404e1c4 GSEventRunModal + 217
	24  GraphicsServices                    0x0404e289 GSEventRun + 115
	25  UIKit                               0x01ce2c93 UIApplicationMain + 1160
	26  ???                                 0x0a0c2754 0x0 + 168568660
	27  ???                                 0x0a0c1ad2 0x0 + 168565458
	28  ???                                 0x0a0be2f2 0x0 + 168551154
	29  ???                                 0x0a0be3cd 0x0 + 168551373
	30  Crux                                0x0000f507 mono_jit_runtime_invoke + 1332
	31  Crux                                0x001ed259 mono_runtime_invoke + 137
	32  Crux                                0x001ef940 mono_runtime_exec_main + 669
	33  Crux                                0x001eed2a mono_runtime_run_main + 843
	34  Crux                                0x000a3093 mono_jit_exec + 200
	35  Crux                                0x002a163d main + 4060
	36  Crux                                0x00002819 _start + 208
	37  Crux                                0x00002748 start + 40
	38  ???                                 0x00000002 0x0 + 2

Debug info from gdb:

dyld: could not load inserted library: /Users/jrmorgan/Library/Application Support/iPhone Simulator/4.3.2/Applications/A98B6C2E-4383-4B7D-99FB-FAC117F8C95A/Rumination.Crux.iOS.Universal.app/monotouch-fixes.dylib


I did not encounter this before updating to MT

It happens both in simulator and on device. I added the UIApplicationExitsOnSuspend=YES key to my Info.plist to reproduce this every time by clicking the home button in the simulator.

It happens still when I remove anything [of mine] that runs on shutdown (UIApplicationDelegate overrides: OnResignActivation(), WillTerminate()).

It happens still when I remove anything [of mine] that runs off the main thread (on the assumption that the "thr_ret" assertion is "thread_return").

Just to keep things spicy: after the app crashes and I quit the simulator, a "sh" process is left behind sucking down 50% CPU time, which I then have to force quit.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2011-08-09 06:12:51 UTC
I tried adding UIApplicationExitsOnSuspend=YES to TweetStation's Info.plist, and I couldn't reproduce a crash. Can you attach a project that crashes for you?
Comment 2 rumination.xamarin 2011-08-09 22:03:13 UTC
It appears to be some strange interaction between System.IO.File.ReadAllLines() and System.Timers.Timer. Test case attached.
Comment 3 rumination.xamarin 2011-08-09 22:04:23 UTC
Created attachment 105 [details]
Test case
Comment 4 Rolf Bjarne Kvinge [MSFT] 2011-08-10 08:51:18 UTC
Is this always reproducible for you? And which XCode version do you have installed?

I've tried your test case, but it doesn't crash for me, neither on the device nor in the simulator.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2011-08-10 09:01:07 UTC
OK, looking that the source code where it crashes it turns out this crash has been fixed some time ago.

It should be fixed when MonoTouch 4.1 comes out, if you can still reproduce after that please reopen this bug.
Comment 6 rumination.xamarin 2011-08-10 10:10:27 UTC
Yes, it's always reproducible for me on both sim & multiple devices. Perhaps some others can try the test case.

I have XCode 4.0.2 (4A2002a) running on Snow Leopard.

"Fixed some time ago" doesn't help me if the bits haven't yet been released. Is there an ETA for MT 4.1? If it's not coming real soon now then I'd appreciate some elaboration on this problem. If you understand it from looking at the source then what should I avoid doing to keep it at bay?
Comment 7 Rolf Bjarne Kvinge [MSFT] 2011-08-10 11:41:47 UTC
This is the fix: https://github.com/mono/mono/commit/2b487789c8e3dcc3fbbcb16bb0268f88718cf8d0

It seems to indicate that one possible workaround would be to wait for other threads to finish before exiting.

We're trying to get MT 4.1 to the alpha/beta channels this week.