URLSession / CFNetwork Crashing

I've been working on an app that uses URLSession's dataTask to pull data from an FTP server. I know it's deprecated but unfortunately the only public API the system I'm working with offers is FTP-based.

About once in every 150-200 connections I'll randomly get a EXC_BAD_ACCESS crash that seems to come from somewhere in CFNetwork. Hoping maybe someone can make more sense of it than I've been able to. The previous version of the app that I wrote for iOS 6 using NSURLConnection doesn't appear to have this problem.

Answered by DTS Engineer in 730088022

So, let’s start you off with my On FTP post. It say:

There is at least one known crashing bug (r. 35745763)

Based on the backtrace in your crash report, I believe you’re hitting this bug. I’m not aware of any workaround for this.

You wrote:

The previous version of the app that I wrote for iOS 6 using NSURLConnection doesn't appear to have this problem.

Interesting. NSURLSession and NSURLConnection share a common core, so most low-level problems like this replicate with both APIs. However, it’s possible that NSURLConnection manages to tiptoe through the landmines in this case. Assuming it’s not too much hassle, you might try changing your new app to use NSURLConnection to see if that improves things.

But, realistically, if you have a long-term dependence on FTP for mission critical work then I strongly recommend that you get off the CFNetwork implementation. It’s officially deprecated, is not being actively maintained, and is probably going to accumulate more problems over time.

Alternatively, if the FTP server you’re talking to is on the public Internet, bring up your own server that acts as a front end for it. This has a couple of advantages:

  • You can talk to your server using HTTPS, which is safe and reliable.

  • Your server can use a supported FTP library to talk to the real server.

Share and Enjoy

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

Accepted Answer

So, let’s start you off with my On FTP post. It say:

There is at least one known crashing bug (r. 35745763)

Based on the backtrace in your crash report, I believe you’re hitting this bug. I’m not aware of any workaround for this.

You wrote:

The previous version of the app that I wrote for iOS 6 using NSURLConnection doesn't appear to have this problem.

Interesting. NSURLSession and NSURLConnection share a common core, so most low-level problems like this replicate with both APIs. However, it’s possible that NSURLConnection manages to tiptoe through the landmines in this case. Assuming it’s not too much hassle, you might try changing your new app to use NSURLConnection to see if that improves things.

But, realistically, if you have a long-term dependence on FTP for mission critical work then I strongly recommend that you get off the CFNetwork implementation. It’s officially deprecated, is not being actively maintained, and is probably going to accumulate more problems over time.

Alternatively, if the FTP server you’re talking to is on the public Internet, bring up your own server that acts as a front end for it. This has a couple of advantages:

  • You can talk to your server using HTTPS, which is safe and reliable.

  • Your server can use a supported FTP library to talk to the real server.

Share and Enjoy

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

Thanks for the info. I had read your On FTP post but was kind of hoping I wasn't running into that particular bug because the crashes didn't seem infrequent. 😅

And unfortunately the systems I'm interfacing with aren't (or at least shouldn't be) on the public internet. So each location that wanted to use the app would need to spin up their own front-end server for it.

Looks like I'll be delving into NWFramework and writing my own interface then.

Thanks again. Glad I was at least able to confirm it's a known issue without a fix.

Looks like I'll be delving into [Network framework] and writing my own interface then.

Alternatively, you could get a third-party library for this. I’m pretty sure libcurl would do what you want.

If I were writing this myself, I’d first create a Swift async wrapper for NWConnection and then write my FTP protocol module using Swift concurrency. That’s a great option for dealing with these old school line-based Internet protocols.

Share and Enjoy

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

URLSession / CFNetwork Crashing
 
 
Q