App mysteriously crashing in CFNetwork.LoaderQ queue

I’m stuck with repeated production crashes in my SwiftUI app and I can’t make sense of the traces on my own.

The symbolicated reports show the same pattern:

Crash on com.apple.CFNetwork.LoaderQ with EXC_BAD_ACCESS / PAC failure

Always deep in CFNetwork, most often in

URLConnectionLoader::loadWithWhatToDo(NSURLRequest*, _CFCachedURLResponse const*, long, URLConnectionLoader::WhatToDo)

No frames from my code, no sign of AuthManager or tokens.

What I’ve tried:

  • Enabled Address Sanitizer,
  • Malloc Scribble,
  • Guard Malloc,
  • Zombies.
  • Set CFNETWORK_DIAGNOSTICS=3 and collected Console logs.
  • Stress-tested the app (rapid typing, filter switching, background/foreground, poor network with Network Link Conditioner).

Could not reproduce the crash locally.

So far:

Logs show unrelated performance faults (I/O on main thread, CLLocationManager delegate), but no obvious CFNetwork misuse.

My suspicion is a URLSession lifetime or delegate/auth-challenge race, but I can’t confirm because I can’t trigger it.

Since starting this investigation, I also refactored some of my singletons into @State/@ObservedObject dependencies. For example, my app root now wires up AuthManager, BackendService, and AccountManager (where API calls happen using async/await) as @State properties:

@State var authManager: AuthManager
@State var accountManager: AccountManager
@State var backendService: BackendService

init() {
  let authManager = AuthManager()
  self._authManager = .init(wrappedValue: authManager)
  let backendService = BackendService(authManager: authManager)
  self._backendService = .init(wrappedValue: backendService)
  self._accountManager = .init(wrappedValue: AccountManager(backendService: backendService))
}

I don’t know if this refactor is related to the crash, but I am including it to be complete.

Apologies that I don’t have a minimized sample project — this issue seems app-wide, and all I have are the crash logs.

Request:

Given the crash location (URLConnectionLoader::loadWithWhatToDo), can Apple provide guidance on known scenarios or misuses that can lead to this crash?

Is there a way to get more actionable diagnostics from CFNetwork beyond CFNETWORK_DIAGNOSTICS to pinpoint whether it’s session lifetime, cached response corruption, or auth/redirect?

Can you also confirm whether my dependency setup above could contribute to URLSession or backend lifetime issues?

I can’t reliably reproduce the crash, and without Apple’s insight the stack trace is effectively opaque to me.

Thanks for your time and help. Happy to send multiple symbolicated crash logs at request.

Thanks for any help.

PS. Including 2 of many similar crash logs. Can provide more if needed.

Answered by DTS Engineer in 856860022

Assuming that your crash reports can be trusted [1], the key failure here is in _dispatch_source_set_runloop_timer_4CF, which definitely rings some bells. Check out my response on this thread.

IMPORTANT That response suggest a potential workaround, and I’d love to hear back from you as to whether that helps or not.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Your crash reports make it clear that you have third-party crash reporter installed (to wit, in your firs crash report, frame 2 of thread 10), and it’s not uncommon for third-party crash reports to mess up the Apple crash reporter. I talk about that issue in great detail in Implementing Your Own Crash Reporter.

However, in this case I think it’s reasonable to trust the crash report because the crash is so familiar.

Assuming that your crash reports can be trusted [1], the key failure here is in _dispatch_source_set_runloop_timer_4CF, which definitely rings some bells. Check out my response on this thread.

IMPORTANT That response suggest a potential workaround, and I’d love to hear back from you as to whether that helps or not.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Your crash reports make it clear that you have third-party crash reporter installed (to wit, in your firs crash report, frame 2 of thread 10), and it’s not uncommon for third-party crash reports to mess up the Apple crash reporter. I talk about that issue in great detail in Implementing Your Own Crash Reporter.

However, in this case I think it’s reasonable to trust the crash report because the crash is so familiar.

The property you're referring to (usesClassicLoadingMode) is available on 18.4+ (wouldn't help for my users who are on iOS 17 and early 18) and it's true by default on the shared URLSession which I use throughout the entire app. I don't use any other session, no custom configurations. I just use Task a lot.

Yet I still get crash reports from users on 18.6.2. Therefore I think it's safe to say it doesn't help.

As per the crashlogs -> I would most certainly and happily get rid of a third party one, but it delivers more reports that Apple's own one. Perhaps I am doing something wrong but in the Organizer there's just less of them.

Looking at Organizer though, the same crash report is also there and when I open the .xccrashpoint and dig in the folder structure and open any of the .crash items in the Logs directory, the same thread crashes occur:

Thread 10 name:
Thread 10 Crashed:
0   libdispatch.dylib             	0x00000001a181de08 _dispatch_source_set_runloop_timer_4CF + 36 (source.c:1349)
1   CFNetwork                     	0x000000019ae29ed8 URLConnectionLoader::loadWithWhatToDo(NSURLRequest*, _CFCachedURLResponse const*, long, URLConnectionLoader::WhatToDo) + 960 (URLConnectionLoader.cpp:1778)
...

Would that mean we can rule out the third party crash reporter messing up the crashes?

Anyway, is there anything else I could do? The error is not going away and the crash rate is around 2% of my users. This is the only big bug causing issues in my app.

I am more than happy to spend time debugging and trying solutions.

it's true by default on the shared URLSession which I use throughout the entire app.

Right. My suggestion was to set it to false, thereby enabling the new loading mode.

If you see this crash with the new loading mode enabled, that’d be a useful datapoint.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Right, sorry. I created this extension:

extension URLSession {

    static var `default`: URLSession {
        if #available(iOS 18.4, *) {
            let config = URLSessionConfiguration.default
            config.usesClassicLoadingMode = false
            return URLSession(configuration: config)
        } else {
            return URLSession.shared
        }
    }

}

And I replaced all URLSession.shared with URLSession.default.

Will deploy it to production and get back to you in a few weeks to see if it helped on newer systems. Please correct me if I did something wrong.

App mysteriously crashing in CFNetwork.LoaderQ queue
 
 
Q