otest crash with –

Tenemos una class que utiliza AFHTTPClient y AFHTTPRequestOperation internamente. En desarrollo, nos conectamos a un server con un Certificado SSL no válido, por lo que tenemos este código en el método que devuelve las operaciones de request:

 if (self.allowInvalidSSLCertificates) { [operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) { if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { [challenge.sender useCnetworkingential:[NSURLCnetworkingential cnetworkingentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; } }]; [operation setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) { return YES; }]; } 

que efectivamente es lo mismo que definir _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_ , pero necesitábamos hacer esto en time de ejecución. Esto funciona perfectamente en Xcode, ignora el certificate no válido y pasan todas nuestras testings funcionales. El problema viene cuando los ejecutamos desde la línea de command usando xcodebuild . Tan pronto como se va a ejecutar la primera testing, se bloquea:

Run test case <testMethodName> Test Case '-[<TestCaseClass> <testMethodName>]' started. /Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include: line 415: 47744 Bus error: 10 "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}" /Applications/Xcode.app/Contents/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Developer/usr/bin/otest' exited abnormally with code 138 (it may have crashed).

Si nos deshacemos de ese código y no ignoramos que el certificate SSL no es válido, las testings no pasan, porque la connection falla, pero nada falla.

Este es el logging de locking en la console:

 Process: otest [35957] Path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Developer/usr/bin/otest Identifier: otest Version: ??? (???) Code Type: X86 (Native) Parent Process: bash [35952] Date/Time: 2012-05-29 15:46:37.398 -0700 OS Version: Mac OS X 10.7.4 (11E53) Report Version: 9 Crashed Thread: 7 com.apple.NSURLConnectionLoader Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000 VM Regions Near 0: --> __PAGEZERO 0000000000000000-0000000000001000 [ 4K] ---/--- SM=NUL /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Developer/usr/bin/otest __TEXT 0000000000001000-0000000000003000 [ 8K] rx/rwx SM=COW /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Developer/usr/bin/otest Thread 0: 0 libsystem_kernel.dylib 0x98908c22 mach_msg_trap + 10 1 libsystem_kernel.dylib 0x989081f6 mach_msg + 70 2 CoreFoundation 0x0045e10a __CFRunLoopServiceMachPort + 186 3 CoreFoundation 0x003c1550 __CFRunLoopRun + 1312 4 CoreFoundation 0x003c0d84 CFRunLoopRunSpecific + 212 5 CoreFoundation 0x003c0c9b CFRunLoopRunInMode + 123 6 Foundation 0x0004e40f -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 7 Foundation 0x000899e8 -[NSRunLoop(NSRunLoop) runUntilDate:] + 73 8 Functional Tests 0x052f37d5 -[<TestCaseClass> <TestMethodName>] + 1253 (<TestCaseClass>.m:564) 9 CoreFoundation 0x003f04ed __invoking___ + 29 10 CoreFoundation 0x003f0407 -[NSInvocation invoke] + 167 11 SenTestingKit 0x201039c4 -[SenTestCase invokeTest] + 184 12 SenTestingKit 0x20103868 -[SenTestCase performTest:] + 183 13 SenTestingKit 0x201034a9 -[SenTest run] + 82 14 SenTestingKit 0x20106db2 -[SenTestSuite performTest:] + 106 15 SenTestingKit 0x201034a9 -[SenTest run] + 82 16 SenTestingKit 0x20106db2 -[SenTestSuite performTest:] + 106 17 SenTestingKit 0x201034a9 -[SenTest run] + 82 18 SenTestingKit 0x20105e97 +[SenTestProbe runTests:] + 174 19 CoreFoundation 0x0048bd51 +[NSObject performSelector:withObject:] + 65 20 otest 0x0000231c 0x1000 + 4892 21 otest 0x000025be 0x1000 + 5566 22 otest 0x00002203 0x1000 + 4611 23 otest 0x00001f8d 0x1000 + 3981 24 otest 0x00001f31 0x1000 + 3889 Thread 1: 0 libsystem_kernel.dylib 0x9890b90a kevent + 10 1 libdispatch.dylib 0x01029372 _dispatch_mgr_invoke + 918 2 libdispatch.dylib 0x01027be1 _dispatch_mgr_thread + 53 Thread 2: 0 libsystem_kernel.dylib 0x9890b02e __workq_kernreturn + 10 1 libsystem_c.dylib 0x9aabcccf _pthread_wqthread + 773 2 libsystem_c.dylib 0x9aabe6fe start_wqthread + 30 Thread 3: 0 libsystem_kernel.dylib 0x9890b02e __workq_kernreturn + 10 1 libsystem_c.dylib 0x9aabcccf _pthread_wqthread + 773 2 libsystem_c.dylib 0x9aabe6fe start_wqthread + 30 Thread 4: 0 libsystem_kernel.dylib 0x9890b02e __workq_kernreturn + 10 1 libsystem_c.dylib 0x9aabcccf _pthread_wqthread + 773 2 libsystem_c.dylib 0x9aabe6fe start_wqthread + 30 Thread 5: 0 libsystem_kernel.dylib 0x9890b02e __workq_kernreturn + 10 1 libsystem_c.dylib 0x9aabcccf _pthread_wqthread + 773 2 libsystem_c.dylib 0x9aabe6fe start_wqthread + 30 Thread 6: 0 libsystem_kernel.dylib 0x98908c22 mach_msg_trap + 10 1 libsystem_kernel.dylib 0x989081f6 mach_msg + 70 2 CoreFoundation 0x0045e10a __CFRunLoopServiceMachPort + 186 3 CoreFoundation 0x003c15d5 __CFRunLoopRun + 1445 4 CoreFoundation 0x003c0d84 CFRunLoopRunSpecific + 212 5 CoreFoundation 0x003c0c9b CFRunLoopRunInMode + 123 6 Foundation 0x0004e40f -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 7 Foundation 0x0004e2d3 -[NSRunLoop(NSRunLoop) run] + 76 8 Functional Tests 0x054fb7f5 +[AFURLConnectionOperation networkRequestThreadEntryPoint:] + 133 (AFURLConnectionOperation.m:146) 9 Foundation 0x0001a4d6 -[NSThread main] + 76 10 Foundation 0x0001a447 __NSThread__main__ + 1258 11 libsystem_c.dylib 0x9aabaed9 _pthread_start + 335 12 libsystem_c.dylib 0x9aabe6de thread_start + 34 Thread 7 Crashed:: com.apple.NSURLConnectionLoader 0 CoreFoundation 0x0039a811 CFArrayGetCount + 17 1 Security 0x00dae356 SecTrustCopyExceptions + 35 2 CFNetwork 0x00b31764 SocketStream::securityAcceptPeerTrust_NoLock(unsigned char) + 150 3 CFNetwork 0x00b39fd4 SocketStream::setProperty(void const*, __CFString const*, void const*) + 2754 4 CFNetwork 0x00b39508 virtual thunk to SocketStream::setProperty(void const*, __CFString const*, void const*) + 43 5 CFNetwork 0x00b3abad ReadStreamCallbacks::_setProperty(__CFReadStream*, __CFString const*, void const*, void*) + 53 6 CoreFoundation 0x00429b10 CFReadStreamSetProperty + 160 7 CFNetwork 0x00b3ab60 HTTPReadFilter::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 266 8 CFNetwork 0x00bd4345 non-virtual thunk to HTTPReadFilter::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 41 9 CFNetwork 0x00b37308 CFNetworkReadStream::httpStreamSetProperty(__CFReadStream*, __CFString const*, void const*, void*) + 38 10 CoreFoundation 0x00429b10 CFReadStreamSetProperty + 160 11 CFNetwork 0x00b419f4 HTTPNetStreamInfo::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 404 12 CFNetwork 0x00b41858 non-virtual thunk to HTTPNetStreamInfo::streamSetProperty(__CFReadStream*, __CFString const*, void const*) + 41 13 CFNetwork 0x00b37308 CFNetworkReadStream::httpStreamSetProperty(__CFReadStream*, __CFString const*, void const*, void*) + 38 14 CoreFoundation 0x00429b10 CFReadStreamSetProperty + 160 15 CFNetwork 0x00be3e29 HTTPProtocol::useCnetworkingential(_CFURLCnetworkingential const*, _CFURLAuthChallenge*) + 125 16 CFNetwork 0x00bfa98f URLConnectionLoader::loaderUseCnetworkingential(_CFURLCnetworkingential const*) + 117 17 CFNetwork 0x00bfa47a URLConnectionLoader::LoaderConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XLoaderEvent, XLoaderEventParams>*, long) + 140 18 CFNetwork 0x00b2273b URLConnectionLoader::processEvents() + 107 19 CFNetwork 0x00bf7117 non-virtual thunk to URLConnectionInstanceData::multiplexerClientPerform() + 21 20 CFNetwork 0x00b20fbf MultiplexerSource::perform() + 259 21 CoreFoundation 0x0045e94f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 22 CoreFoundation 0x003c1b43 __CFRunLoopDoSources0 + 243 23 CoreFoundation 0x003c1424 __CFRunLoopRun + 1012 24 CoreFoundation 0x003c0d84 CFRunLoopRunSpecific + 212 25 CoreFoundation 0x003c0c9b CFRunLoopRunInMode + 123 26 Foundation 0x00108e30 +[NSURLConnection(Loader) _resourceLoadLoop:] + 398 27 Foundation 0x0001a4d6 -[NSThread main] + 76 28 Foundation 0x0001a447 __NSThread__main__ + 1258 29 libsystem_c.dylib 0x9aabaed9 _pthread_start + 335 30 libsystem_c.dylib 0x9aabe6de thread_start + 34 Thread 8:: com.apple.CFSocket.private 0 libsystem_kernel.dylib 0x9890ab42 __select + 10 1 CoreFoundation 0x003f27cb __CFSocketManager + 939 2 libsystem_c.dylib 0x9aabaed9 _pthread_start + 335 3 libsystem_c.dylib 0x9aabe6de thread_start + 34 Thread 7 crashed with X86 Thread State (32-bit): eax: 0x00000000 ebx: 0x00000002 ecx: 0x0d651da4 edx: 0x05012980 edi: 0x0039a80d esi: 0x00000000 ebp: 0xb038bbb8 esp: 0xb038bba0 ss: 0x00000023 efl: 0x00010286 eip: 0x0039a811 cs: 0x0000001b ds: 0x00000023 es: 0x00000023 fs: 0x00000023 gs: 0x0000000f cr2: 0x00000000 Logical CPU: 4 Binary Images: ..... 

Buscar en Google para ese locking no muestra nada similar. Se cuelga dentro de CFNetwork con un EXC_BAD_ACCESS , y no puedo ver ningún problema de administración de memory en AFNetworking o en mi código que podría estar causando esto. Además, esto no sucede el 100% de las veces (diría que alnetworkingedor del 80%), así que no puedo evitar pensar que hay algún tipo de condición de carrera. ¿Tal vez estamos haciendo algo con un object no apto para subprocesss en el hilo incorrecto? Una vez más, no he visto nada en particular en este sentido.

Usando Xcode 4.3.2 en Mac OSX 10.7.4

Como dije en github, también tuve este locking (same stackstrace), pero no se bloquea cuando se inicia un simulador de iOS …

Editar: encontró una solución (no muy conveniente, pero la continuous integration volvió 🙂

 @interface NSURLRequest ()

 + (void) setAllowsAnyHTTPSCertificate: (BOOL) b forHost: (NSString *) host;

 @fin

 @implementation SomeTests

 - (vacío) setUp
 {
     [NSURLRequest setAllowsAnyHTTPSCertificate: YES forHost: @ "domain.com"];
 }
 ...