gpt4 book ai didi

CFNetwork 中的 SIGABRT 导致 iOS 崩溃

转载 作者:可可西里 更新时间:2023-11-01 03:20:48 25 4
gpt4 key购买 nike

我通过扩展 NSURLProtocol 在我的应用程序中使用自定义 url 协议(protocol)。它大部分时间都运行良好,但我看到通过 crashlytics 报告了以下崩溃。我无法自己重现这个。最让我担心的是,我没有在崩溃线程的堆栈跟踪中看到我的应用程序,所以我不知道从哪里开始调试。下面是崩溃报告

Thread : Crashed: com.apple.NSURLConnectionLoader
0 libsystem_kernel.dylib 0x3562cc84 __pthread_kill + 8
1 libsystem_pthread.dylib 0x356d0733 pthread_kill + 62
2 libsystem_c.dylib 0x355c4f21 abort + 108
3 libsystem_c.dylib 0x355a47eb __assert_rtn + 302
4 CFNetwork 0x22b82e45 CFURLProtocol_NS::_protocolInterface_cancelLoad() + 322
5 CFNetwork 0x22c3740f ___ZN19URLConnectionLoader27_private_ScheduleOriginLoadEPK12NSURLRequestPK20_CFCachedURLResponse_block_invoke_2 + 38
6 CFNetwork 0x22b66ccd ___ZNK19URLConnectionLoader25withExistingProtocolAsyncEU13block_pointerFvP11URLProtocolE_block_invoke + 16
7 libdispatch.dylib 0x35513bd7 _dispatch_client_callout + 22
8 libdispatch.dylib 0x3551d187 _dispatch_block_invoke$VARIANT$mp + 446
9 CFNetwork 0x22b66caf RunloopBlockContext::_invoke_block(void const*, void*) + 18
10 CoreFoundation 0x2326ab51 CFArrayApplyFunction + 36
11 CFNetwork 0x22b66b97 RunloopBlockContext::perform() + 182
12 CFNetwork 0x22b66a61 MultiplexerSource::perform() + 216
13 CFNetwork 0x22b668f9 MultiplexerSource::_perform(void*) + 48
14 CoreFoundation 0x23319bff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
15 CoreFoundation 0x233197ed __CFRunLoopDoSources0 + 452
16 CoreFoundation 0x23317b5b __CFRunLoopRun + 794
17 CoreFoundation 0x2326b119 CFRunLoopRunSpecific + 520
18 CoreFoundation 0x2326af05 CFRunLoopRunInMode + 108
19 CFNetwork 0x22bd8bbf +[NSURLConnection(Loader) _resourceLoadLoop:] + 486
20 Foundation 0x241291b5 __NSThread__start__ + 1148
21 libsystem_pthread.dylib 0x356cf85b _pthread_body + 138
22 libsystem_pthread.dylib 0x356cf7cf _pthread_start + 110
23 libsystem_pthread.dylib 0x356cd724 thread_start + 8

堆栈跟踪中有趣的部分是这几行..

4  CFNetwork                      0x22b82e45 CFURLProtocol_NS::_protocolInterface_cancelLoad() + 322
5 CFNetwork 0x22c3740f ___ZN19URLConnectionLoader27_private_ScheduleOriginLoadEPK12NSURLRequestPK20_CFCachedURLResponse_block_invoke_2 + 38
6 CFNetwork 0x22b66ccd ___ZNK19URLConnectionLoader25withExistingProtocolAsyncEU13block_pointerFvP11URLProtocolE_block_invoke + 16

我可以通过查看 NSURLProtocol 中 startLoading 和 stopLoading 方法的堆栈跟踪来确定 ___ZN19URLConnectionLoader27_private_ScheduleOriginLoadEPK12NSURLRequestPK20_CCFachedURLResponse_block_invoke_2 调用 startLoading 而 CFURLProtocol_NS::_protocolLoading_cancel> 调用 stopLoading()取消请求。那么,为什么或如何在尝试开始加载后立即调用取消?

非常感谢任何帮助。谢谢。

更新:

我能够重现类似的(不是精确的跟踪)并且我看到以下断言..

Assertion failed: (_protocolInstance == nil), function _protocolInterface_startLoad, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/CFNetwork/CFNetwork-758.0.2/Session/LocalSession.mm, line 1341.

下面是回溯。

(lldb) bt
* thread #6: tid = 0xe687, 0x34515d24 libsystem_kernel.dylib`__pthread_kill + 8, name = 'com.apple.NSURLConnectionLoader', stop reason = signal SIGABRT
* frame #0: 0x34515d24 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x345b974a libsystem_pthread.dylib`pthread_kill + 62
frame #2: 0x344adf40 libsystem_c.dylib`abort + 108
frame #3: 0x3448d80a libsystem_c.dylib`__assert_rtn + 302
frame #4: 0x2202de4c CFNetwork`CFURLProtocol_NS::_protocolInterface_startLoad(_CFCachedURLResponse const*) + 324
frame #5: 0x220e22e6 CFNetwork`___ZN19URLConnectionLoader27_private_ScheduleOriginLoadEPK12NSURLRequestPK20_CFCachedURLResponse_block_invoke_2 + 38
frame #6: 0x22011cd4 CFNetwork`___ZNK19URLConnectionLoader25withExistingProtocolAsyncEU13block_pointerFvP11URLProtocolE_block_invoke + 16
frame #7: 0x003a5d72 libdispatch.dylib`_dispatch_client_callout + 22
frame #8: 0x003ad8d8 libdispatch.dylib`_dispatch_block_invoke + 468
frame #9: 0x22011cb6 CFNetwork`RunloopBlockContext::_invoke_block(void const*, void*) + 18
frame #10: 0x22710c80 CoreFoundation`CFArrayApplyFunction + 36
frame #11: 0x22011b9e CFNetwork`RunloopBlockContext::perform() + 182
frame #12: 0x22011a68 CFNetwork`MultiplexerSource::perform() + 216
frame #13: 0x22011900 CFNetwork`MultiplexerSource::_perform(void*) + 48
frame #14: 0x227bfc3e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
frame #15: 0x227bf7c0 CoreFoundation`__CFRunLoopDoSources0 + 344
frame #16: 0x227bdb9a CoreFoundation`__CFRunLoopRun + 794
frame #17: 0x22711248 CoreFoundation`CFRunLoopRunSpecific + 520
frame #18: 0x22711034 CoreFoundation`CFRunLoopRunInMode + 108
frame #19: 0x22083ee6 CFNetwork`+[NSURLConnection(Loader) _resourceLoadLoop:] + 486
frame #20: 0x235cc634 Foundation`__NSThread__start__ + 1148
frame #21: 0x345b8872 libsystem_pthread.dylib`_pthread_body + 138
frame #22: 0x345b87e6 libsystem_pthread.dylib`_pthread_start + 110
frame #23: 0x345b6740 libsystem_pthread.dylib`thread_start + 8

这是我的协议(protocol)类的简化版本,其中 MyConnection 的工作方式与 NSURLConnection 非常相似。

@实现我的协议(protocol)

- (void) startLoading {
NSURLRequest *request = self.request;
self.myConnection = [[MyConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
NSRunLoop *loop = [NSRunLoop currentRunLoop];
[self.myConnection scheduleInRunLoop:loop forMode:loop.currentMode];
[self.myConnection start];
}

- (void) stopLoading {
if (self.myConnection) {
[self.myConnection cancel];
self.myConnection = nil;
}
}

#pragma mark MyConnectionDelegate


- (void) myConnection:(MyConnection *)connection didReceiveData:(NSData *)data {
[self.client URLProtocol:self didLoadData:data];
}

- (void) myConnectionDidFinishLoading:(MyConnection *)connection {
[self.client URLProtocolDidFinishLoading:self];
}

//..other delegate methods are implemented similarly

之间,我看到的异常代码是

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 4

最佳答案

我不知道你是否已经这样做了,但也许尝试强制开始和取消在同一个线程上?

尝试使用-com.apple.CoreData.ConcurrencyDebug 1 用于调试 - 我不确定它是否只调试 CoreData 线程,但值得一试。

关于CFNetwork 中的 SIGABRT 导致 iOS 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33364686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com