内部でAFHTTPClient
とを使用するクラスがあります。AFHTTPRequestOperation
開発中は、無効なSSL証明書を使用してサーバーに接続するため、リクエスト操作を返すメソッドに次のコードが含まれています。
if (self.allowInvalidSSLCertificates)
{
[operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
}];
[operation setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) {
return YES;
}];
}
これは事実上定義と同じですが_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
、実行時にこれを行う必要がありました。これはXcodeで完全に機能し、無効な証明書を無視し、すべての機能テストに合格します。を使用してコマンドラインから実行すると、問題が発生しxcodebuild
ます。最初のテストを実行するとすぐに、クラッシュします。
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).
そのコードを削除し、SSL証明書が無効であることを無視しない場合、接続が失敗するため、テストは合格しませんが、何もクラッシュしません。
これは、コンソールのクラッシュログです。
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] r-x/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::useCredential(_CFURLCredential const*, _CFURLAuthChallenge*) + 125
16 CFNetwork 0x00bfa98f URLConnectionLoader::loaderUseCredential(_CFURLCredential 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:
.....
そのクラッシュをグーグルで検索しても、同様のことは何も表示されません。内部CFNetwork
でがクラッシュしEXC_BAD_ACCESS
、AFNetworkingまたはコードでこれを引き起こしている可能性のあるメモリ管理の問題を確認できません。また、これは100%の確率で発生するわけではないので(80%前後だと思います)、何らかの競合状態があると思わずにはいられません。おそらく、間違ったスレッドでスレッドセーフでないオブジェクトを使って何かをしているのでしょうか?繰り返しますが、この点に関しては特に何も見ていません。
MacOSX10.7.4でのXcode4.3.2の使用