DBL_MAX for backgroundTimeRemaining while running in the background

Recently we've started to see DBL_MAX being returned by UIApplication.backgroundTimeRemaining while running in the background and with all background task assertions released. We were expecting the process to suspend itself shortly after relinquishing all task assertions but it does not. This seems to be happening mostly after waking up from a VOIP push. Is this a recent regression in iOS?

I should stress that the meaning of

DBL_MAX
in this context is not formally documented (I know because I tried to get it documented and the responsible engineer didn’t want it to be). Then again,
backgroundTimeRemaining
is not very useful other than for logging — remember that your background tasks can be ‘called in’ at any time, so the value in
backgroundTimeRemaining
doesn’t help you very much — so this little ambiguity doesn’t seem like a big deal to me.

I generally interpret

DBL_MAX
to mean that something other than a UIApplication background task is preventing the process from suspending, something without a timeout. The most obvious cause of this is your app being in the foreground, but there are plenty of other scenarios where it would make sense (like location tracking or an audio session).

That are you using

backgroundTimeRemaining
for?

Also, you wrote:

Recently …

What do you mean by “recently”? On iOS 11 beta? Or on some builds in the iOS 10 range?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

We haven't really paid much attention to this until recently, so I would say in the iOS 10 range is where DBL_MAX seems to be showing up more when running in the background.


We are using it only for logging, but the issue we are running into is that the process isn't suspending when we expect it to. And then it gets weirder: the process continues to run for a bit longer, and then it suddenly gets suspended -- even with active bg task assertions -- and magically we don't get killed. None of the expiration handlers gets called in this scenario. 😕

We are using it only for logging, but the issue we are running into is that the process isn't suspending when we expect it to.

That, in and of itself, is not a bug; the OS is not required to suspend your task at all, let alone on any particular schedule. But yeah, it’s definitely weird and could be a symptom of some deeper issue.

And then it gets weirder: the process continues to run for a bit longer, and then it suddenly gets suspended -- even with active bg task assertions …

But that most definitely is a bug. If you can get it to happen on demand, you should definitely file a bug report about it, making sure to include a sysdiagnose. Please post your bug number, just for the record.

Assuming, of course, that it’s not a bug in your code. I’ve seen similar reports like this in the past and it often comes down to folks ‘leaking’ or ‘over releasing’ a UIApplication background task.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
DBL_MAX for backgroundTimeRemaining while running in the background
 
 
Q