What is the watchdog, and what causes the 0x8badf00d exception?
Predict first
Where in the crash report do you look first for a 0x8badf00d termination?
// A: the exception code only
// B: the main thread’s (thread 0) backtrace
// C: the memory section
- A
- B
- C
Mental model. A lifeguard watching the pool. You are allowed to be slow getting in, but if you are not out of the changing room by the deadline, they close the pool.
The watchdog is a system supervisor that terminates an app that fails to make progress in a required time. It applies at specific moments: launching (the app must finish launching and show its first frame), resuming from the background, and finishing background work (a task or transition that does not complete in time). The kill carries the exception code 0x8badf00d (“ate bad food”), and appears in a crash-style report with the reason, such as “scene-create watchdog transgression” or an expired background task.
The cause is almost always the main thread being blocked at that moment: a synchronous network request or database migration in didFinishLaunching, a deadlock or long lock wait, heavy work in a scene callback, or a background task that never ends. Read the report’s thread 0 backtrace: it shows what the main thread was doing when the time ran out. Fixes: do the minimum before the first frame and move the rest off the main thread or after launch, give long work to a background queue or task, always end background tasks and respect expiration handlers, and measure hangs with MetricKit and Instruments. The watchdog does not care why you are slow, only that you are.
It shows what the main thread was doing when the deadline passed, which is nearly always the blocked call to fix.
Common traps
- Running a database migration in
didFinishLaunching. On a large store it exceeds the launch limit on slow devices. - Forgetting to end a background task. The expiry then terminates the app, even though the work finished.
They might follow up with
- Does the debugger hide the watchdog? Yes. It is disabled while attached, so reproduce on a device without Xcode attached.
- How is it different from a hang? A hang is the UI not responding for a while; the watchdog is the system acting on a hang at a critical moment.