I have an HTTP networking library based on NSURLConnection, whose unit tests crash very reliably when run on the iOS 4.3 simulator. But that’s the _only_ context in which I get a crash: the tests run fine on Mac OS (Lion), and apps using the library work fine on Mac and iOS. I can’t tell whether this crash is a bug in the simulator, or a real problem in my code that’s for some reason only manifesting in this situation.
The crash is on the internal NSURLConnection background thread. What seems to be happening is that CFRunLoopCopyCurrentMode returns NULL, and then MultiplexerSource::_wakeupRunLoop passes that to CFEqual, which crashes. Here’s the backtrace:
#0 0x003c2d80 in CFEqual () #1 0x009669a0 in MultiplexerSource::_wakeupRunLoop () #2 0x0096694a in _apply () #3 0x003eb4e9 in __CFSetApplyFunction_block_invoke_1 () #4 0x003d7435 in CFBasicHashApply () #5 0x003eb486 in CFSetApplyFunction () #6 0x00966923 in CFNSchedulingSetApplyFunction () #7 0x009668d8 in MultiplexerSource::signal () #8 0x00966827 in RunLoopMultiplexer::signal () #9 0x00a3ac1a in URLConnectionClient::scheduleClientCallbacksLocked () #10 0x00966555 in URLConnectionClient::pushEvents () #11 0x0098cff1 in URLConnectionLoader::protocolDidFinishLoading () #12 0x0098cf34 in HTTPProtocol::endEncountered () #13 0x0098bd17 in HTTPProtocol::httpReadStreamEvent () #14 0x0045a953 in _signalEventSync () #15 0x0045a8be in _cfstream_shared_signalEventSync () #16 0x0048c8ff in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ () #17 0x003ea88b in __CFRunLoopDoSources0 () #18 0x003e9d86 in __CFRunLoopRun () #19 0x003e9840 in CFRunLoopRunSpecific () #20 0x003e9761 in CFRunLoopRunInMode () #21 0x0005b102 in +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] () #22 0x00025cf4 in -[NSThread main] () #23 0x00025c80 in __NSThread__main__ () #24 0x9712ced9 in _pthread_start () #25 0x971306de in thread_start ()
The recent instructions in _wakeupRunLoop are:
0x00966984 <+0056> mov 0x8(ëp),êx 0x00966987 <+0059> mov êx,(%esp) 0x0096698a <+0062> call 0xa644c8 <dyld_stub_CFRunLoopCopyCurrentMode> 0x0096698f <+0067> mov êx,%esi 0x00966991 <+0069> mov êx,0x4(%esp) 0x00966995 <+0073> mov 0xc(ëp),êx 0x00966998 <+0076> mov êx,(%esp) 0x0096699b <+0079> call 0xa64384 <dyld_stub_CFEqual>
and the parameters passed to CFEqual are:
(gdb) x/2x $esp 0xb0183bc0: 0x00dda144 0x00000000
The first parameter (dda144) is the name of my custom runloop mode that the NSURLConnection has been scheduled in. The second is NULL, which is the value returned by CFRunLoopCopyCurrentMode.
All this time, the main thread is inside a call to -[NSRunLoop runMode:beforeDate:].
Anyone have any idea what’s going on here?
—Jens |