Alamofire: CFNetwork HTTPProtocol::shouldAttemptOriginLoad() crash on iOS 12

Created on 15 May 2019  ·  9Comments  ·  Source: Alamofire/Alamofire

ℹ Please fill out this template when filing an issue.
All lines beginning with an ℹ symbol instruct you with what info we expect. You can delete those lines once you've filled in the info.

Per our *CONTRIBUTING guidelines, we use GitHub for
bugs and feature requests, not general support. Other issues should be opened on Stack Overflow with the tag alamofire.

Please remove this line and everything above it before submitting.

What did you do?

I am sending request with Alamofire/Moya/RxSwift.

What did you expect to happen?

get response normally

What happened instead?

get tons of crashes on HTTPProtocol::shouldAttemptOriginLoad() crash on iOS 12

Alamofire Environment

*Alamofire version: 4.1
*
Xcode version: 10.1
*Swift version: 4.2
*
Platform(s) running Alamofire: iOS
**macOS version running Xcode: 10.14.2

Demo Project

I know this is an issue of CFNetwork. but what's weird is it only happens on Alamofire
Some guys posted the crash reports I've noticed they are using Alamofire/Moya/RxSwift
We've got another team in our department, they are using AFNetworking. they never get this issue
It's very possible that Alamofire is using something that trigger CFNetwork bug all the time
If you get any idea please let me know.
If this can be fixed, we have to find alternative

Please check these links
https://stackoverflow.com/questions/55662368/how-to-fix-cfnetwork-issue-ios-swift/56140824#56140824
https://forums.developer.apple.com/message/346841#346841

needs feedback needs investigation

Most helpful comment

As you can see by the crash log, Alamofire isn't a part of the call stack here, so unless the underlying cause is found, it's hard for us to do anything to mitigate it (if we even can). I see from the Apple forums post that people have filed Apple bugs about the issue. That's the best way for them to investigate this and recommend workaround. If you do get a response and they give you a cause, feel free to reply again and let us know so we can integrate a fix. Until then, however, there's isn't much we can do. I'll leave this issue open for a week or so to maintain visibility.

All 9 comments

This happens to me too. I have like 200+ crashes in the last 30 days because of this

Wondering if this happens only with Alamofire? I haven't tried other networking libraries

Here's a crash report from Crashlytics:

Crashed: com.apple.CFNetwork.LoaderQ
0  CFNetwork                      0x235ba0d10 HTTPProtocol::shouldAttemptOriginLoad() + 36
1  CFNetwork                      0x235ba0d04 HTTPProtocol::shouldAttemptOriginLoad() + 24
2  CFNetwork                      0x235ba08cc HTTPProtocol::_protocolInterface_startLoad(_CFCachedURLResponse const*) + 388
3  CFNetwork                      0x235bfd770 invocation function for block in URLConnectionLoader::_private_ScheduleOriginLoad(NSURLRequest const*, _CFCachedURLResponse const*) + 88
4  CFNetwork                      0x235bfb1bc invocation function for block in URLConnectionLoader::withExistingProtocolAsync(void (URLProtocol*) block_pointer) const + 32
5  CFNetwork                      0x235cc5e0c invocation function for block in QCoreSchedulingSet::performAsync(void () block_pointer) const + 52
6  libdispatch.dylib              0x234f0ca38 _dispatch_call_block_and_release + 24
7  libdispatch.dylib              0x234f0d7d4 _dispatch_client_callout + 16
8  libdispatch.dylib              0x234ee8dec _dispatch_lane_serial_drain$VARIANT$armv81 + 548
9  libdispatch.dylib              0x234ee9964 _dispatch_lane_invoke$VARIANT$armv81 + 464
10 libdispatch.dylib              0x234eeabd0 _dispatch_workloop_invoke$VARIANT$armv81 + 1900
11 libdispatch.dylib              0x234ef1e08 _dispatch_workloop_worker_thread + 584
12 libsystem_pthread.dylib        0x2350ed114 _pthread_wqthread + 304
13 libsystem_pthread.dylib        0x2350efcd4 start_wqthread + 4

I'm referring to this apple forum thread as well for any response we might get from the Apple team: https://forums.developer.apple.com/thread/110493

Alamofire Environment

Alamofire version: 4.8.1
Xcode version: 10.2.1
Swift version: 5.0
Platform(s) running Alamofire: iOS
macOS version running Xcode: 10.14.4

As you can see by the crash log, Alamofire isn't a part of the call stack here, so unless the underlying cause is found, it's hard for us to do anything to mitigate it (if we even can). I see from the Apple forums post that people have filed Apple bugs about the issue. That's the best way for them to investigate this and recommend workaround. If you do get a response and they give you a cause, feel free to reply again and let us know so we can integrate a fix. Until then, however, there's isn't much we can do. I'll leave this issue open for a week or so to maintain visibility.

FWIW, the crashlogs on SO look like a memory trashing bug. OP could try to turn on malloc debugging and Zombies to see if that catches anything.

I've never seen this on my device, it's the crash log of online users collected by Crash Analysis SDK

Curiously I did see it when running unit tests a few days ago after my above comments. I realized I've seen it a handful of times over the past few months when running unit tests in a current app I'm working on, although I ignored it those times as just some random fluke event. I followed my own advice, turned on malloc debugging and zombies and ran the unit tests about 30 times but never saw the crash again.

When I sat there in the debugger looking at the crash I wasn't sure what I would report to Apple in a bug report anyway. I just saw the stack trace that was similar to what's shown above. I was hoping I could reproduce it and report that, but it didn't reproduce.

Even though you don't see the crash during development doesn't mean that the bug isn't there. You know that the crash sometimes happens when running your app. Having malloc debugging and zombies on during development might make the crash happen more often and you might be able to correlate something in your app with the crash.

I don't think this crash is related to Alamofire at all.
If you look at this thread https://forums.developer.apple.com/thread/110493, there's a response from Sykj on June the 4th, 2019. He says he's been able to reproduce this crash constantly and provided some demo code. I too was able to reproduce the crash, with the same demo code, at least once in two times of running the app.
Apple team says they're going to look into this issue, so I think best we can do is wait for their reply.

I ran into this while running unit tests in a couple of my projects. It wasn't reproducible per se but did happen with some regularity. I filed a bug with Apple and they closed it as a dupe within 24 hours. They didn't ask for any additional info.

Looking at the example code in the forum it also resembles some of my unit tests that cancel the request shortly after starting them.

Thanks for the update @arnold-plakolli. I'll leave this issue open for now as we wait to see if Apple recommends a workaround. Maybe they'll fix it for iOS 13! If we don't hear anything soon, I'll close the issue.

Doesn't look like there's anything for us to do here. If anyone comes up with a workaround, feel free to share.

Was this page helpful?
0 / 5 - 0 ratings