iOS11 watchdog timeout crashes (0x8badf00d) but code not on stack

Hi,


I am debugging user reports of our app repeatedly exiting while in the background starting in iOS11, even during active use (for example, the user backgrounds us and returns within a few seconds or a minute, only to find it restarted). Here is the relevant bit from one such crash log:


Exception Type: EXC_CRASH (SIGKILL)

Exception Codes: 0x0000000000000000, 0x0000000000000000

Exception Note: EXC_CORPSE_NOTIFY

Termination Reason: Namespace <0xF>, Code 0x8badf00d

Triggered by Thread: 0


I realize that our code has a limited period of time during which to operation when receiving push notifications or when backgrounded. We definitely do use UIBackgroundTasks (with Alamofire Networking, FWIW), and we do have expiration handlers that do this:


    backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
        [application endBackgroundTask:backgroundTask];
        backgroundTask = UIBackgroundTaskInvalid; /
        DebugLog(@"Ended because expiration");
    }];


The most perplexing thing about these crash reports is that our code is nowhere on the stacks. We can see from this Apple discussion of the 0x8badf00d exception code, the offending code is, in fact, being actively executed on the main thread.


However, in my case, none of the stacks ever have any of my code being executed. Here is one representative sample:


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib         0x0000000183208bc4 0x183208000 + 3012
1   libsystem_kernel.dylib         0x0000000183208a3c 0x183208000 + 2620
2   CoreFoundation                 0x00000001836b9c4c 0x1835d0000 + 957516
3   CoreFoundation                 0x00000001836b7818 0x1835d0000 + 948248
4   CoreFoundation                 0x00000001835d7e78 0x1835d0000 + 32376
5   GraphicsServices               0x000000018546cf84 0x185462000 + 44932
6   UIKit                         0x000000018d37a0bc 0x18d307000 + 471228
7   MyApp                         0x0000000102a6572c main + 87852 (main.m:22)
8   libdyld.dylib                 0x00000001830fa56c 0x1830f9000 + 5484


Thread 1 name:  com.apple.uikit.eventfetch-thread
Thread 1:
0   libsystem_kernel.dylib         0x0000000183208bc4 0x183208000 + 3012
1   libsystem_kernel.dylib         0x0000000183208a3c 0x183208000 + 2620
2   CoreFoundation                 0x00000001836b9c4c 0x1835d0000 + 957516
3   CoreFoundation                 0x00000001836b7818 0x1835d0000 + 948248
4   CoreFoundation                 0x00000001835d7e78 0x1835d0000 + 32376
5   Foundation                     0x00000001840006e4 0x183ff4000 + 50916
6   Foundation                     0x000000018401fafc 0x183ff4000 + 178940
7   UIKit                         0x000000018ded9630 0x18d307000 + 12396080
8   Foundation                     0x0000000184101860 0x183ff4000 + 1103968
9   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
10  libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
11  libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 2 name:  com.twitter.crashlytics.ios.MachExceptionServer
Thread 2:
0   libsystem_kernel.dylib         0x0000000183208bc4 0x183208000 + 3012
1   libsystem_kernel.dylib         0x0000000183208a3c 0x183208000 + 2620
2   MyApp                         0x0000000102cdaad8 CLSMachExceptionServer + 100
3   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
4   libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
5   libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 3 name:  com.apple.NSURLConnectionLoader
Thread 3:
0   libsystem_kernel.dylib         0x0000000183208bc4 0x183208000 + 3012
1   libsystem_kernel.dylib         0x0000000183208a3c 0x183208000 + 2620
2   CoreFoundation                 0x00000001836b9c4c 0x1835d0000 + 957516
3   CoreFoundation                 0x00000001836b7818 0x1835d0000 + 948248
4   CoreFoundation                 0x00000001835d7e78 0x1835d0000 + 32376
5   CFNetwork                     0x0000000183d41de0 0x183c93000 + 716256
6   Foundation                     0x0000000184101860 0x183ff4000 + 1103968
7   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
8   libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
9   libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 4 name:  AVAudioSession Notify Thread
Thread 4:
0   libsystem_kernel.dylib         0x0000000183208bc4 0x183208000 + 3012
1   libsystem_kernel.dylib         0x0000000183208a3c 0x183208000 + 2620
2   CoreFoundation                 0x00000001836b9c4c 0x1835d0000 + 957516
3   CoreFoundation                 0x00000001836b7818 0x1835d0000 + 948248
4   CoreFoundation                 0x00000001835d7e78 0x1835d0000 + 32376
5   AVFAudio                       0x0000000189615774 0x189591000 + 542580
6   AVFAudio                       0x0000000189640018 0x189591000 + 716824
7   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
8   libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
9   libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 5:
0   libsystem_kernel.dylib         0x0000000183229150 0x183208000 + 135504
1   libsystem_pthread.dylib       0x000000018333ed30 0x18333a000 + 19760
2   libc++.1.dylib                 0x00000001828e3ea4 0x1828dc000 + 32420
3   JavaScriptCore                 0x000000018b157d00 0x18a812000 + 9723136
4   JavaScriptCore                 0x000000018b157c28 0x18a812000 + 9722920
5   JavaScriptCore                 0x000000018b157f8c 0x18a812000 + 9723788
6   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
7   libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
8   libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 6 name:  WebThread
Thread 6:
0   libsystem_kernel.dylib         0x0000000183208bc4 0x183208000 + 3012
1   libsystem_kernel.dylib         0x0000000183208a3c 0x183208000 + 2620
2   CoreFoundation                 0x00000001836b9c4c 0x1835d0000 + 957516
3   CoreFoundation                 0x00000001836b7818 0x1835d0000 + 948248
4   CoreFoundation                 0x00000001835d7e78 0x1835d0000 + 32376
5   WebCore                       0x000000018bc1c75c 0x18bbdb000 + 268124
6   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
7   libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
8   libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 7 name:  WebCore: LocalStorage
Thread 7:
0   libsystem_kernel.dylib         0x0000000183229150 0x183208000 + 135504
1   libsystem_pthread.dylib       0x000000018333ed30 0x18333a000 + 19760
2   JavaScriptCore                 0x000000018a81fa18 0x18a812000 + 55832
3   JavaScriptCore                 0x000000018b13da04 0x18a812000 + 9615876
4   WebKitLegacy                   0x000000018d00f5fc 0x18cf7c000 + 603644
5   WebKitLegacy                   0x000000018d01226c 0x18cf7c000 + 615020
6   WebKitLegacy                   0x000000018d011998 0x18cf7c000 + 612760
7   JavaScriptCore                 0x000000018a81c010 0x18a812000 + 40976
8   JavaScriptCore                 0x000000018a81bf50 0x18a812000 + 40784
9   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
10  libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
11  libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 8 name:  com.apple.CFSocket.private
Thread 8:
0   libsystem_kernel.dylib         0x0000000183229570 0x183208000 + 136560
1   CoreFoundation                 0x00000001836c2184 0x1835d0000 + 991620
2   libsystem_pthread.dylib       0x000000018333c31c 0x18333a000 + 8988
3   libsystem_pthread.dylib       0x000000018333c1e8 0x18333a000 + 8680
4   libsystem_pthread.dylib       0x000000018333ac28 0x18333a000 + 3112


Thread 9:
0   libsystem_pthread.dylib       0x000000018333ac1c 0x18333a000 + 3100


Thread 10:
0   libsystem_kernel.dylib         0x0000000183229dbc 0x183208000 + 138684
1   libsystem_pthread.dylib       0x000000018333afa0 0x18333a000 + 4000
2   libsystem_pthread.dylib       0x000000018333ac20 0x18333a000 + 3104


Thread 11:
0   libsystem_pthread.dylib       0x000000018333ac1c 0x18333a000 + 3100


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000010004005   x1: 0x0000000007000806   x2: 0x0000000000000000   x3: 0x0000000000000c00
    x4: 0x0000000000002b03   x5: 0x00000000ffffffff   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x00000000fffffbbf   x9: 0x0000000007000000  x10: 0x0000000007000100  x11: 0x0000000000000040
   x12: 0xffffffffffffffff  x13: 0x0000000000000001  x14: 0x01e8540001e85400  x15: 0x0000000000000000
   x16: 0xffffffffffffffe1  x17: 0x00000000ffffffff  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x00000000ffffffff  x21: 0x0000000000002b03  x22: 0x0000000000000c00  x23: 0x000000016d3aed38
   x24: 0x0000000007000806  x25: 0x0000000000000000  x26: 0x0000000007000806  x27: 0x0000000000000c00
   x28: 0x0000000000000001   fp: 0x000000016d3aec30   lr: 0x0000000183208a3c
    sp: 0x000000016d3aebe0   pc: 0x0000000183208bc4 cpsr: 0x60000000



The only part of my code that is running is main.m, line 22, which is


int retVal = UIApplicationMain(argc, argv, nil, @"PSSMyAppDelegate");


Thus, I am perplexed as to how my app could be repeatedly killed for running time violations when it would seem that none of my code is, in fact, running. Is there anything new in iOS 11 that could change the behavior of the watchdog process? If not, how can I tell what part of my code is the part that is in violation for running too long?

Hi
im facing the same issue
Date/Time: 2020-06-29 14:28:27.1411 +0300
Launch Time: 2020-06-29 13:59:00.5354 +0300
OS Version: iPhone OS 13.5.1 (17F80)
Release Type: User
Baseband Version: 7.60.01
Report Version: 104

Exception Type: EXCCRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC
CORPSENOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Termination Description: SPRINGBOARD, scene-update watchdog transgression: application<com.securingsam.base>:3167 exhausted real (wall clock) time allowance of 10.00 seconds | ProcessVisibility: Foreground | ProcessState: Running | WatchdogEvent: scene-update | WatchdogVisibility: Background | WatchdogCPUStatistics: ( | "Elapsed total CPU time (seconds): 4.410 (user 4.410, system 0.000), 21% CPU", | "Elapsed application CPU time (seconds): 0.199, 1% CPU" | )
Triggered by Thread: 0

Thread 0 name: Dispatch queue: com.apple.uikit.backgroundTaskAssertionQueue
Thread 0 Crashed:
0 libsystem
kernel.dylib 0x00000001a321677c _ulockwait + 8
1 libsystemplatform.dylib 0x00000001a3125ef0 osunfairlocklockslow + 192
2 AssertionServices 0x00000001a7bb58d4 -[BKSAssertion invalidateSynchronously:] + 40
3 AssertionServices 0x00000001a7bba254 -[BKSProcessAssertion invalidate] + 92
4 UIKitCore 0x00000001a74e64b8
36-[UIApplication endBackgroundTask:]blockinvoke.3402 + 272
5 UIKitCore 0x00000001a74ba0c8 -[UIObjectReferenceCounter decrementReferenceForObject:invalidationHandler:] + 288
6 UIKitCore 0x00000001a74e6374
36-[UIApplication endBackgroundTask:]blockinvoke + 320
7 libdispatch.dylib 0x00000001a30e6524 dispatchclientcallout + 16
8 libdispatch.dylib 0x00000001a30990b0
dispatchlanebarriersyncinvokeandcomplete + 56
9 UIKitCore 0x00000001a74e60d0 -[UIApplication endBackgroundTask:] + 864
10 UIKitCore 0x00000001a74d17c8
65-[UIApplication beginSnapshotSessionForScene:withSnapshotBlock:]blockinvoke.2181 + 376
11 UIKitCore 0x00000001a74d2028 _65-[UIApplication performSnapshotsWithAction:forScene:completion:]blockinvoke.2202 + 132
12 FrontBoardServices 0x00000001a85de3cc -[FBSSceneSnapshotAction finishAllRequests] + 64
13 FrontBoardServices 0x00000001a85de58c -[FBSSceneSnapshotAction
executeNextRequest] + 340
14 FrontBoardServices 0x00000001a85de58c -[FBSSceneSnapshotAction executeNextRequest] + 340
15 FrontBoardServices 0x00000001a85de128 -[FBSSceneSnapshotAction executeRequestsWithHandler:completionHandler:expirationHandler:] + 276
16 UIKitCore 0x00000001a74d1e60
65-[UIApplication performSnapshotsWithAction:forScene:completion:]blockinvoke2 + 280
17 UIKitCore 0x00000001a74d13c8 -[UIApplication
beginSnapshotSessionForScene:withSnapshotBlock:] + 1028
18 UIKitCore 0x00000001a74d1d20 _65-[UIApplication performSnapshotsWithAction:forScene:completion:]blockinvoke + 132
19 UIKitCore 0x00000001a6add438 -[UIScene enableOverrideSettingsForActions:] + 60
20 UIKitCore 0x00000001a6add6b8 -[UIScene
performSystemSnapshotWithActions:] + 120
21 UIKitCore 0x00000001a74d1a9c -[UIApplication performSnapshotsWithAction:forScene:completion:] + 468
22 UIKitCore 0x00000001a7a0c968
98-[UISceneSnapshotBSActionsHandler respondToActions:forFBSScene:inUIScene:fromTransitionContext:]blockinvoke3 + 168
23 UIKitCore 0x00000001a7a0c7f0 _98-[UISceneSnapshotBSActionsHandler respondToActions:forFBSScene:inUIScene:fromTransitionContext:]blockinvoke2 + 468
24 UIKitCore 0x00000001a6adccb4 -[UIScene emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 664
25 UIKitCore 0x00000001a6addcac -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 220
26 UIKitCore 0x00000001a7063afc -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 464
27 FrontBoardServices 0x00000001a85980a8 -[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:] + 528
28 FrontBoardServices 0x00000001a85bc684
88-[FBSWorkspaceScenesClient sceneID:updateWithSettingsDiff:transitionContext:completion:]blockinvoke2 + 120
29 FrontBoardServices 0x00000001a85a1bfc -[FBSWorkspace calloutQueueexecuteCalloutFromSource:withBlock:] + 232
30 FrontBoardServices 0x00000001a85bc5b8 _88-[FBSWorkspaceScenesClient sceneID:updateWithSettingsDiff:transitionContext:completion:]blockinvoke + 184
31 libdispatch.dylib 0x00000001a30e6524
dispatchclientcallout + 16
32 libdispatch.dylib 0x00000001a308f434 dispatchblockinvokedirect$VARIANT$mp + 224
33 FrontBoardServices 0x00000001a85e0850 FBSSERIALQUEUEISCALLINGOUTTOABLOCK + 40
34 FrontBoardServices 0x00000001a85e051c -[FBSSerialQueue queueperformNextIfPossible] + 404
35 FrontBoardServices 0x00000001a85e0a44 -[FBSSerialQueue performNextFromRunLoopSource] + 28
36 CoreFoundation 0x00000001a339ec18 CFRUNLOOP
ISCALLINGOUTTOASOURCE0PERFORMFUNCTION + 24
37 CoreFoundation 0x00000001a339eb70
CFRunLoopDoSource0 + 80
38 CoreFoundation 0x00000001a339e2f8
CFRunLoopDoSources0 + 184
39 CoreFoundation 0x00000001a3399328
_CFRunLoopRun + 788
40 CoreFoundation 0x00000001a3398ce8 CFRunLoopRunSpecific + 424
41 GraphicsServices 0x00000001ad4e338c GSEventRunModal + 160
42 UIKitCore 0x00000001a74c7444 UIApplicationMain + 1932
43 Telenet 0x0000000104f5eef4 0x104efc000 + 405236
44 libdyld.dylib 0x00000001a32208f0 start + 4


it happen some time While testing the app, I have noticed a lot of crashes when re-opening the app. Especially when you close the app (not killing app). Re-opening almost always result in app not responding or crash.

please advice
iOS11 watchdog timeout crashes (0x8badf00d) but code not on stack
 
 
Q