Scene create violation when launching app in the background

Hi,


We have reports from several users that our app fails to launch in the background. The app could launch in the background due to a background fetch event.


After analyzing their logs, we see the following:


[com.app.id] Provision violated for watchdog scene-create: <FBSProcessResourceProvision: 0x1108d7d10; allowance: <; FBSProcessResourceAllowance; type: scheduledTime; timeValue: 3.77s>; violated: YES>

[com.app.id] Executing termination for reason (none) with request: <FBSProcessTerminationRequest: 0x107abbfb0; label: "watchdog provision violated"; exceptionCode: "Watchdog Violation (0x8BADF00D)"; reportType: CrashLog; explanation: "scene-create watchdog transgression: com.app.id exhausted CPU time allowance of 3.77 seconds">


The app seems to be already running, since I see this:


[app:1849] Attempting to acquire assertion for app:1849: <BKProcessAssertion: 0x100735de0; "com.lapp.launch_sequence.bgtask" (finishTask:180s); id:…7A9D83D792D1>


So at some point during the launch sequence(didFinishLaunching...), we were able to request a background task assertion.


And here we get such assertion:


[app:1849] Add assertion: <BKProcessAssertion: 0x100735de0; id: 1849-FAE26CB2-AC0A-4EC6-AD1E-7A9D83D792D1; name: com.app.launch_sequence.bgtask; state: active; reason: finishTask; duration: 180.0s> {

owner = <BSProcessHandle: 0x10073a8b0; app:1849; valid: YES>;

flags = preventSuspend, preventIdleSleep, preventSuspendOnSleep;

}


Is there a way to get more information why we are just given 3.77 seconds? I thought the allowance was around 20 seconds. This is after dylib, could this mean we are taking almost 16 seconds during framework loading, and thus only left with almost 4s during didFinishLaunching?


Found the crash logs:


Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d

Termination Description: SPRINGBOARD, scene-create watchdog transgression: com.app.id exhausted CPU time allowance of 3.77 seconds | | ProcessVisibility: Background | ProcessState: Running | WatchdogEvent: scene-create | WatchdogVisibility: Background | WatchdogCPUStatistics: ( | "Elapsed total CPU time (seconds): 10.270 (user 10.270, system 0.000), 57% CPU", | "Elapsed application CPU time (seconds): 5.082, 28% CPU" | )

Triggered by Thread: 0



Filtered syslog:
None found


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   CoreFoundation                 0x00000001824ef088 +[NSDictionary dictionaryWithObject:forKey:] + 0
1   UIKit                         0x000000018c190708 -[UIApplication _deactivateForReason:notify:] + 616
2   UIKit                         0x000000018c19f948 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2428
3   UIKit                         0x000000018c7cfa0c __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 784
4   UIKit                         0x000000018c19ee4c +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 160
5   UIKit                         0x000000018c19ece8 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 240
6   UIKit                         0x000000018c19db78 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 724
7   UIKit                         0x000000018ce3372c __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 296
8   UIKit                         0x000000018c19d268 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 432
9   UIKit                         0x000000018cc189b8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 220
10  UIKit                         0x000000018cd66ae8 _performActionsWithDelayForTransitionContext + 112
11  UIKit                         0x000000018c19cc88 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 248
12  UIKit                         0x000000018c19c624 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 368
13  UIKit                         0x000000018c19965c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 540
14  UIKit                         0x000000018c1993ac -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 364
15  FrontBoardServices             0x0000000184e00470 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 364
16  FrontBoardServices             0x0000000184e08d6c __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 224
17  libdispatch.dylib             0x0000000181ef4ae4 _dispatch_client_callout + 16
18  libdispatch.dylib             0x0000000181efc1f4 _dispatch_block_invoke_direct$VARIANT$mp + 224
19  FrontBoardServices             0x0000000184e34878 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
20  FrontBoardServices             0x0000000184e3451c -[FBSSerialQueue _performNext] + 404
21  FrontBoardServices             0x0000000184e34ab8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
22  CoreFoundation                 0x00000001825ab404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
23  CoreFoundation                 0x00000001825aac2c __CFRunLoopDoSources0 + 276
24  CoreFoundation                 0x00000001825a879c __CFRunLoopRun + 1204
25  CoreFoundation                 0x00000001824c8da8 CFRunLoopRunSpecific + 552
26  GraphicsServices               0x00000001844ab020 GSEventRunModal + 100
27  UIKit                         0x000000018c4a978c UIApplicationMain + 236

the same with me, any way to resolve ?

Is there a way to get more information why we are just given 3.77 seconds? I thought the allowance was around 20 seconds.

IMPORTANT The watchdog timeouts are not documented because they change over time. The values I’m posting here are for debugging purposes only.

The watchdog will terminate your app in a number of situations. The one that folks most offer encounter is the launch timeout, and you’re correct that you can reasonably expect about 20 seconds there. However, there are many others, and many of those have much shorter timeouts. For example, I added this code to my app delegate:

func applicationWillEnterForeground(_ application: UIApplication) {
    NSLog("QQQ will enter foreground")
    Thread.sleep(forTimeInterval: 10.0)
}

and got a watchdog crash report like this:

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Termination Description: 
    SPRINGBOARD, 
    scene-update watchdog transgression: 
    com.example.apple-samplecode.xxsi 
    exhausted real (wall clock) time allowance of 10.00 seconds 
    | ProcessVisibility: Foreground 
    | ProcessState: Running 
    | WatchdogEvent: scene-update 
    | WatchdogVisibility: Foreground 
    | WatchdogCPUStatistics: ( 
    | "Elapsed total CPU time (seconds): 3.610 (user 3.610, system 0.000), 18% CPU", 
    | "Elapsed application CPU time (seconds): 0.005, 0% CPU" 
    | )
Triggered by Thread:  0

That is, when you come to the front, the watchdog requires you to respond within (roughly) 3.5 seconds.

Share and Enjoy

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

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

Hi,


Have you managed to resolve the issue?

I am experiencing exactly the same for some users.

Scene create violation when launching app in the background
 
 
Q