0xc51bad03 crash on watchOS3.1

My watch app uses background refresh tasks heavily, and work during task is asynchronous. Sometimes (once in 15-20 background task executions) it gets terminated by OS with 0xc51bad03 reason. Release notes of watchOS3.1 say:


Background Refresh Violations of system resources will result in a crash report for your application. The exception code provides context about the nature of the violation:

  • 0xc51bad01 The app used too much CPU time.
  • 0xc51bad02 The app took too much wall time.
  • 0xc51bad03 The app may not have had sufficient runtime to complete the task.

What does this "may not have had sufficient runtime" mean? What can be possible reason? This kill code have not been explained during WWDC sessions. Looks like this crash does not depend on exact place in my code that is executed at the moment.


Crash report except does not make reason clearer:


Exception Type: EXC_CRASH (SIGKILL)

Exception Codes: 0x0000000000000000, 0x0000000000000000

Exception Note: EXC_CORPSE_NOTIFY

Termination Reason: Namespace SPRINGBOARD, Code 0xc51bad03

Triggered by Thread: 0


Filtered syslog:

None found


Thread 0 name: Dispatch queue: com.apple.main-thread

Thread 0 Crashed:

0 libsystem_kernel.dylib 0x264216d0 mach_msg_trap + 20

1 libsystem_kernel.dylib 0x2642149c mach_msg + 40

2 CoreFoundation 0x267aed88 __CFRunLoopServiceMachPort + 154

3 CoreFoundation 0x267ad04c __CFRunLoopRun + 1068

4 CoreFoundation 0x26701f74 CFRunLoopRunSpecific + 354

5 Foundation 0x2704307c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 246

6 Foundation 0x2708ff5a -[NSRunLoop(NSRunLoop) run] + 80

7 libxpc.dylib 0x265330de _xpc_objc_main + 600

8 libxpc.dylib 0x265346fe xpc_main + 166

9 Foundation 0x27217fea service_connection_handler + 0

10 PlugInKit 0x303eb1be -[PKService run] + 774

11 WatchKit 0x342efe00 main + 134

12 libdyld.dylib 0x26344566 start + 2


...

Replies

First up, some terminology (you probably understand this stuff already but I want to be sure)…

  • CPU time is time spent executing code on the actual CPU

  • wall time is the time as measured by the system clock (it’s called this because it matches, literally, a clock on the wall)

That explains 0xc51bad01 and 0xc51bad02. OTOH, it doesn’t help with 0xc51bad03.

0xc51bad03 means that the app did not complete the task within the required amount of wall time. However, this may not be the app’s fault because the system was busy and may not have been able to give the app sufficient CPU time.

There may not be a lot your app can do about this. Reducing the CPU time taken for the task might help (in that it may then fit under a lower bar) but there’s no guarantees.

Looks like this crash does not depend on exact place in my code that is executed at the moment.

Right. The crash report you posted is kinda what I’d expect. You’ve run out of wall time without getting CPU time, so it stands to reason that your main thread is blocked in the run loop.

Do you get backtraces for other threads? If so, they may indicate what your code was doing at the time.

ps I’ve filed a bug requesting that this explanation be expanded (r. 30284237).

Share and Enjoy

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

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