CFNetwork assertion

Hi all,

Sometimes my app crashes with an assertion:
Code Block
Assertion failed: (CFReadStreamGetStatus(_stream.get()) == kCFStreamStatusNotOpen), function _onqueue_setupStream_block_invoke, file /Library/Caches/com.apple.xbs/Sources/CFNetwork/CFNetwork-1126/HTTP/Core/IO/HTTPRequestBody.cpp, line 861.


The stack trace is not very useful as well:
Code Block
Thread 11 name:
Thread 11 Crashed:
0 libsystem_kernel.dylib 0x00000001892ed9a4 pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001891fdc64 pthread_kill + 272 (pthread.c:1375)
2 libsystem_c.dylib 0x0000000189185c74 abort + 116 (abort.c:147)
3 libsystem_c.dylib 0x0000000189185c00 abort + 116 (abort.c:118)
4 libsystem_c.dylib 0x0000000189184f10 assert_rtn + 292 (assert.c:96)
5 CFNetwork 0x000000018cd3969c invocation function for block in RequestBodyStream::_onqueue_setupStream() + 256 (HTTPRequestBody.cpp:871)
6 libdispatch.dylib 0x0000000189192394 _dispatch_client_callout + 20 (object.m:559)
7 libdispatch.dylib 0x0000000189195a6c _dispatch_block_invoke_direct + 268 (queue.c:468)
8 CFNetwork 0x000000018cd9b9b8 RunloopBlockContext::_invoke_block(void const*, void*) + 44 (CoreSchedulingSet.mm:367)
9 CoreFoundation 0x00000001894096a4 CFArrayApplyFunction + 84 (CFArray.c:699)
10 CFNetwork 0x000000018cd9b8cc RunloopBlockContext::perform() + 132 (CoreSchedulingSet.mm:321)
11 CFNetwork 0x000000018cd9de80 MultiplexerSource::_perform(void*) + 304 (CFNRunLoopMultiplexer.c:267)
12 CoreFoundation 0x0000000189473124 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 (CFRunLoop.c:1967)
13 CoreFoundation 0x0000000189473068 CFRunLoopDoSource0 + 176 (CFRunLoop.c:2011)
14 CoreFoundation 0x000000018947268c CFRunLoopDoSources0 + 240 (CFRunLoop.c:2048)
15 CoreFoundation 0x000000018946cd7c CFRunLoopRun + 828 (CFRunLoop.c:2925)
16 CoreFoundation 0x000000018946c630 CFRunLoopRunSpecific + 564 (CFRunLoop.c:3242)
17 CFNetwork 0x000000018cd9c9ac +[CFN_CoreSchedulingSetRunnable _run:] + 592 (CoreSchedulingSet.mm:1374)
18 Foundation 0x00000001899692f8 NSThreadstart + 864 (NSThread.m:724)
19 libsystem_pthread.dylib 0x00000001891fcc98 _pthread_start + 320 (pthread.c:880)
20 libsystem_pthread.dylib 0x0000000189205788 thread_start + 8


Is there anything that I can try to understand what it's causing the crash?

As a general rule, if an assertion fires in an Apple framework, that’s always bugworthy. Do you have an Apple crash report for this? If so, please file a bug and then post the bug number here.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Yes, I have the crash report 🤓. It's attached to the bug: FB8026062

Thanks!

I had a look at the info in your bug and it seems very likely that this is a bug in CFNetwork itself. Some factoids:
  • It affects a wide variety of apps.

  • It seems very likely that it’s an iOS 13 regression (we’ve not seen it on iOS 12).

We’ve been tracking this internally (r. 56379199) but there’s no sign of a fix.

How is your app using CFNetwork? Via NSURLSession? Or via some lower-level API, like NSStream?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
The app mainly uses Alamofire and it uses both NSURLSession and NSStream as far as I can see, but I can assume that the majority of our calls uses NSURLSession under the hood. We also have third party sdks and some of them are closed source so I cannot guarantee what are they using. I know that this is not very useful...
Is there anything else that I can do to verify this? Swizzling some NSStream methods or use symbolic breakpoints in debug to see if is it used?
How easy is it for you to reproduce this?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
It's quite easy. Sometimes it takes a bit longer, but I can reproduce it systematically.
Hi @luigi176, i'm encountering a very similar issue. i wonder how can you reproduce it? thanks

We came to know an outdated GoogleMaps library was causing the issue.

if you used an InputStream for request body in POST request, don't open it before you send the request

CFNetwork assertion
 
 
Q