Task watchdog got triggered: which task, and why

A task that the ESP-IDF task watchdog watches did not check in within the timeout. Most often the watched task is an idle task, which means some other task kept a CPU to itself.

The line

E (10303) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (10303) task_wdt:  - IDLE0 (CPU 0)
E (10303) task_wdt: Tasks currently running:
E (10303) task_wdt: CPU 0: main
E (10303) task_wdt: CPU 1: IDLE1
E (10303) task_wdt: Print CPU 0 (current core) backtrace

The line formats are those of ESP-IDF v5.4 task_wdt.c; the timestamp and task names are illustrative. Here main on CPU 0 kept IDLE0 from running.

What it means

The task watchdog (TWDT) watches the idle task of each CPU by default, and any task or user that subscribes to it. Each watched entry has to reset the watchdog within the timeout, which is CONFIG_ESP_TASK_WDT_TIMEOUT_S (5 seconds unless changed). The idle task resets it whenever it gets to run, so an idle task in the list means that no CPU time was left over on that core for the whole timeout.

By default this is a warning: ESP-IDF prints the tasks that did not reset the watchdog, the task running on each CPU and a backtrace, and the application keeps running. Only with CONFIG_ESP_TASK_WDT_PANIC set does a timeout go to the panic handler and restart the chip.

Common causes

A task that loops without blocking

The guide’s own description of what the watchdog is for: a task that spins on a peripheral or sits in an endless loop runs for a long time without yielding. Lower priority tasks, the idle task among them, never run on that core. The task to look at is the one listed under Tasks currently running for the CPU of the starved idle task.

Source: ESP-IDF v5.4 Programming Guide: Watchdogs, Task Watchdog Timer (TWDT)

Work that legitimately takes longer than the timeout

A long calculation, or erasing a large flash region, can keep a task on the CPU for longer than the timeout without anything being wrong. The guide’s advice is to set CONFIG_ESP_TASK_WDT_TIMEOUT_S at least as long as any single task needs to hold the CPU, or to split the work so that the task blocks in between.

Source: ESP-IDF v5.4 Programming Guide: Watchdogs, Task Watchdog Timer (TWDT)

A subscribed task that stopped feeding the watchdog

A task added with esp_task_wdt_add() must call esp_task_wdt_reset() periodically. If it blocks forever on a queue, a mutex or a socket, or simply takes a path that skips the call, its own name appears in the list in place of an idle task.

Source: ESP-IDF v5.4 API reference: esp_task_wdt_add() and esp_task_wdt_reset()

Interrupts kept off, which is a different watchdog

When interrupts are blocked by a long critical section or interrupt handler, the scheduler cannot switch tasks either, but the report is usually Interrupt wdt timeout on CPU0 from the interrupt watchdog, as a Guru Meditation Error, not this line. Seeing that one instead points at ISR or critical section length, not at task priorities.

Source: ESP-IDF v5.4 Programming Guide: Watchdogs, Interrupt Watchdog Timer (IWDT)

What to check first

  1. Read the list under the line. IDLE0 or IDLE1 means a core was never idle for the whole timeout; any other name is a task that subscribed and did not call esp_task_wdt_reset().
  2. Read Tasks currently running. The task shown on the CPU of the starved idle task is the one that held it; the backtrace printed next shows where in that task.
  3. Open that code and look for a loop with no blocking call. A loop that polls needs a vTaskDelay() of at least one tick, or a wait on a queue, semaphore or notification, so that lower priority tasks get to run.
  4. If the work is long by design, raise CONFIG_ESP_TASK_WDT_TIMEOUT_S or break the work into steps; do not disable the idle task check just to make the message go away.
  5. If the board restarts after the message, CONFIG_ESP_TASK_WDT_PANIC is on; after that restart esp_reset_reason() returns ESP_RST_TASK_WDT.
  6. When a JTAG debugger is attached through OpenOCD, the task and interrupt watchdogs are disabled at the first breakpoint and stay off, so a missing warning under the debugger proves nothing.

In NeuroTerm

On a serial tab with pattern markers on, NeuroTerm recognises this line as “Board crash: ESP task watchdog”. A coding agent connected through Terminal Use gets that name in its list of tabs and among the markers of the output it reads, with a cursor for reading the lines around it. Setup is in Terminal Use (MCP).