我在VOIP应用程序中看到了CFNetwork内部崩溃的两种不同变种:
第一次出现:
Thread 4 Crashed: 0 ??? 0x20333434 0x0 + 0 1 CoreFoundation 0x2add4c6f CFReadStreamCopyProperty + 108 2 CFNetwork 0x2a898ae9 SPDYConnection::isCellular() + 26 3 CFNetwork 0x2a898a91 SPDYConnection::shouldIdleClose(double, double) + 58 4 CFNetwork 0x2a8a785b ___ZN24SPDYConnectionCacheEntry15shouldIdleCloseEdd_block_invoke + 32 5 CoreFoundation 0x2ad17c7d CFArrayApplyFunction + 34 6 CFNetwork 0x2a8a781f SPDYConnectionCacheEntry::shouldIdleClose(double, double) + 136 7 CFNetwork 0x2a908fdb SPDYConnectionCache::_onqueue_purgeIdleConnections(bool) + 248 8 CFNetwork 0x2a86634d RunloopBlockContext::_invoke_block(void const*, void*) + 58 9 CoreFoundation 0x2ad17c7d CFArrayApplyFunction + 34 10 CFNetwork 0x2a866207 RunloopBlockContext::perform() + 180 11 CFNetwork 0x2a8660cd MultiplexerSource::perform() + 214 12 CFNetwork 0x2a865f61 MultiplexerSource::_perform(void*) + 46 13 CoreFoundation 0x2adcc377 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12 14 CoreFoundation 0x2adcb787 __CFRunLoopDoSources0 + 216 15 CoreFoundation 0x2adc9ded __CFRunLoopRun + 770 16 CoreFoundation 0x2ad18211 CFRunLoopRunSpecific + 474 17 CoreFoundation 0x2ad18023 CFRunLoopRunInMode + 104 18 CFNetwork 0x2a8cdb9f +[NSURLConnection(Loader) _resourceLoadLoop:] + 484 19 Foundation 0x2bb14b5b __NSThread__main__ + 1116 20 libsystem_pthread.dylib 0x38cd0e93 _pthread_body + 136 21 libsystem_pthread.dylib 0x38cd0e07 _pthread_start + 116 22 libsystem_pthread.dylib 0x38cceb90 thread_start + 6
第二次出现:
Thread 4 Crashed: 0 CoreFoundation 0x2c34d1dc CFBasicHashFindBucket + 10416 1 CoreFoundation 0x2c34a8eb CFDictionaryGetValue + 104 2 CFNetwork 0x2bea376d SocketStream::copyProperty(void const*, __CFString const*) + 114 3 CoreFoundation 0x2c41dc6f CFReadStreamCopyProperty + 108 4 CFNetwork 0x2bee1ae9 SPDYConnection::isCellular() + 26 5 CFNetwork 0x2bee1a91 SPDYConnection::shouldIdleClose(double, double) + 58 6 CFNetwork 0x2bef085b ___ZN24SPDYConnectionCacheEntry15shouldIdleCloseEdd_block_invoke + 32 7 CoreFoundation 0x2c360c7d CFArrayApplyFunction + 34 8 CFNetwork 0x2bef081f SPDYConnectionCacheEntry::shouldIdleClose(double, double) + 136 9 CFNetwork 0x2bf51fdb SPDYConnectionCache::_onqueue_purgeIdleConnections(bool) + 248 10 CFNetwork 0x2beaf34d RunloopBlockContext::_invoke_block(void const*, void*) + 58 11 CoreFoundation 0x2c360c7d CFArrayApplyFunction + 34 12 CFNetwork 0x2beaf207 RunloopBlockContext::perform() + 180 13 CFNetwork 0x2beaf0cd MultiplexerSource::perform() + 214 14 CFNetwork 0x2beaef61 MultiplexerSource::_perform(void*) + 46 15 CoreFoundation 0x2c415377 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12 16 CoreFoundation 0x2c414787 __CFRunLoopDoSources0 + 216 17 CoreFoundation 0x2c412ded __CFRunLoopRun + 770 18 CoreFoundation 0x2c361211 CFRunLoopRunSpecific + 474 19 CoreFoundation 0x2c361023 CFRunLoopRunInMode + 104 20 CFNetwork 0x2bf16b9f +[NSURLConnection(Loader) _resourceLoadLoop:] + 484 21 Foundation 0x2d15db5b __NSThread__main__ + 1116 22 libsystem_pthread.dylib 0x3a775e93 _pthread_body + 136 23 libsystem_pthread.dylib 0x3a775e07 _pthread_start + 116 24 libsystem_pthread.dylib 0x3a773b90 thread_start + 6
查看其他线程,第一个变体似乎在可达性发生变化时发生。第二种变体似乎发生在应用程序在后台运行并获得后台任务回调时。
我实际上没有观察到这些崩溃,它们来自曲棍球坠毁报告。
有关如何跟踪此问题的任何想法?
答案 0 :(得分:1)
AFURLConnectionOperation使用同步请求。我不知道为什么他们选择这样做,但IMO,这是一个糟糕的做事方式;同步请求不会让你取消它们,每个请求都会泄漏一点RAM,无法控制缓存等。
我已经看到你在上面发布的回溯,以及整个网络堆栈中随机点的几百个其他崩溃。我能想到的唯一解释是NSURLConnection的某些部分在某些情况下没有正确保留其委托,并且崩溃似乎与同步请求的数量成正比。
我的建议是,如果你绝对必须发出同步请求,请从另一个线程中滚动你自己的同步包装类,它使用NSURLConnection异步,并使用NSCondition允许调用线程在连接完成后继续。
举个例子,看一下我在这里实现的MPSynchronousURLRequest类:
https://github.com/dgatwood/mixpanel-iphone
它为您提供完全透明的sendSynchronousRequest替换,完全由您控制,因此您可以使用缓存行为修改代码,以特定于应用程序的方式处理错误等。