Bug 692247

Summary: ThreadPool issue
Product: [Novell Products] MonoTouch Reporter: Matt Jones <matt>
Component: RuntimeAssignee: Geoff Norton <gnorton>
Status: RESOLVED DUPLICATE QA Contact: Mono Bugs <mono-bugs>
Severity: Critical    
Priority: P5 - None    
Version: SVN   
Target Milestone: ---   
Hardware: iPhone   
OS: Apple iOS 4.3   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Crash log

Description Matt Jones 2011-05-06 11:21:28 UTC
Created attachment 428402 [details]
Crash log

User-Agent:       Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24

I have a hard-to-reproduce problem with ThreadPool. I have a complex multithreaded app that uses a lot of socket comms. In MonoTouch 3.2.6 this did not occur. In 4.00 and 4.01 I had problem with Socket.BeginConnect but no problems with ThreadPool (see here: http://stackoverflow.com/questions/5803114/problem-with-socket-beginconnect-in-monotouch-4-01-was-ok-in-3-2-6).

In 4.02 I get a crash as my app starts on the device - it's fine on the simulator. This crash happens in debug and release builds. Stack trace of the thread that crashed:

Thread 7 Crashed:
0   libsystem_kernel.dylib        	0x32715a1c __pthread_kill + 8
1   libsystem_c.dylib             	0x329c23b4 pthread_kill + 52
2   libsystem_c.dylib             	0x329babf8 abort + 72
3   TradeClient1                  	0x00872344 mono_handle_native_sigsegv (mini-exceptions.c:2249)
4   TradeClient1                  	0x00899c20 sigabrt_signal_handler (mini-posix.c:195)
5   libsystem_c.dylib             	0x329cd728 _sigtramp + 36
6   libsystem_c.dylib             	0x329c23b4 pthread_kill + 52
7   libsystem_c.dylib             	0x329babf8 abort + 72
8   TradeClient1                  	0x009af1a0 monoeg_g_logv (goutput.c:133)
9   TradeClient1                  	0x009af234 monoeg_assertion_message (goutput.c:154)
10  TradeClient1                  	0x00982924 _wapi_handle_unref (handles.c:1143)
11  TradeClient1                  	0x0097fca4 handle_cleanup (handles.c:215)
12  libsystem_c.dylib             	0x329ba902 __cxa_finalize + 154
13  libsystem_c.dylib             	0x329ba84a exit + 6
14  TradeClient1                  	0x0096fdc8 async_invoke_thread (threadpool.c:1444)
15  TradeClient1                  	0x009726c8 start_wrapper_internal (threads.c:782)
16  TradeClient1                  	0x009727bc start_wrapper (threads.c:830)
17  TradeClient1                  	0x00997348 thread_start_routine (wthreads.c:285)
18  TradeClient1                  	0x009c70a4 GC_start_routine (pthread_support.c:1468)
19  libsystem_c.dylib             	0x329c230a _pthread_start + 242
20  libsystem_c.dylib             	0x329c3bb4 thread_start + 0

I have tracked this down to the following code that was being called in my AppDelegate constructor:

public AppDelegate()
{ 
   ThreadPool.QueueUserWorkItem (delegate { 
      Debug.WriteLine("Pre-caching DNS");      
      Dns.GetHostEntry("[a valid dns name]");
      Dns.GetHostEntry("[a valid dns name]"); 
      Dns.GetHostEntry("[a valid dns name]");      
      Dns.GetHostEntry("[a valid dns name]"); 
      Debug.WriteLine("Finished pre-caching DNS"); 
}); }

(I have removed the DNS names as they relate to proprietary services.)

If I move this to the start of the FinishedLaunching method, it seems to work OK. But, I have tried to wrap this in a tiny sample app to demonstrate the problem - and I no longer experience the crash whether it is in the AppDelegate constructor or in FinishedLaunching.

In the sample app I also tried launching 100 different ThreadPool tasks, to try and stimulate the crash, with no success.

The full crash log from my device is attached.

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Comment 1 Geoff Norton 2011-05-06 22:45:45 UTC
This should only happen on app shutdown (something else was causing your app to exit), but we've fixed it too! :)

*** This bug has been marked as a duplicate of bug 688030 ***