Task watchdog on ESP32 after a long receive stall: sync task starves the main loop while catching up

オープン
#223 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Boisti13 がすでに取り組んでいます。

2026年11月3日 から。

  • #224 @Boisti13 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp

調査の方向性

Start with src/sync_task.cpp around SyncTask::process_playback_progress() and the inner loop in SyncTask::thread_entry(), then inspect src/platform/shadow_slot.h and decode_chunk()'s load-time skip behavior. Reproduce a long receive stall with ESP32 watchdog logging and determine whether backlog processing prevents lower-priority tasks from running. Done means a change prevents watchdog resets while preserving correct playback; linked PR #224 is already open.

索引モデルが issue の本文から書いたものです。

説明

Summary

An ESP32 Sendspin player (ESPHome) gets restarted by the task watchdog on core 1 shortly after a long receive stall. The crashed task is SsSync. It looks like the sync task works through the backlog that arrives after the stall without blocking, and at its priority (6, above ESPHome's loopTask at 1) it starves the main loop past the 5 s task-watchdog timeout.

Setup

  • AI-Thinker ESP32-A1S audio kit (ESP32-WROVER, 8 MB PSRAM, ES8388), CPU at 240 MHz
  • ESPHome 2026.10.1, sendspin-cpp 0.9.3 (pulled in by ESPHome)
  • sendspin: task_stack_in_psram: false, media_source: - platform: sendspin, buffer_size: 2500000
  • I2S speaker, 48 kHz, buffer_duration: 100ms
  • Server: Music Assistant 2.10.8; Wi-Fi around -50 to -65 dBm, but the player regularly gets no data for 4–15 s

What happened (2026-11-03, local time)

  • 13:00:35 Music Assistant (aiosendspin) logs Slow send_bytes: 11581.6ms ... role=player
  • ~13:01:05 the player restarts: reset reason task watchdog
  • 13:01:10 server logs WebSocket closed, close_code=1006; the player is back at 13:01:14

Crash record:

Reason: Task wdt
Crashed core: 1
PC: 0x400D7EDA
BT: 0x400D7ED7 0x400D840D 0x400E6FBD 0x400F8A21 0x400F92A7 0x401BEB8B 0x401B0501 0x400D82B4

Decoded with the ELF of that exact build:

pthread_mutex_lock_internal            pthread.c:716
pthread_mutex_lock                     pthread.c:746
std::mutex::lock()                     std_mutex.h:113
sendspin::ShadowSlot<sendspin::PlaybackProgress>::take(...)   src/platform/shadow_slot.h:54
sendspin::SyncTask::process_playback_progress(...)            src/sync_task.cpp:879
sendspin::SyncTask::thread_entry(void*)                       src/sync_task.cpp:1035
std::thread ... execute_native_thread_routine / pthread_task_func

What I think is going on (not verified)

The program counter sits in the playback-progress mutex, which is most likely just where SsSync happened to be when the watchdog fired, not a deadlock: process_playback_progress() runs on every pass of the inner loop. The inner loop only blocks in take_item() (15 ms) when the inbound ring is empty, and in the sink write. After a long stall the ring refills quickly, so LOAD_CHUNK → (skip or decode) → SYNCHRONIZE_AUDIO → LOAD_CHUNK can run back to back. decode_chunk() does skip chunks that are late against new_audio_client_playtime before decoding them, but per #198 that estimate is stale after the sink starves, so after the stall the backlog may still be decoded (and then dropped or played late) rather than skipped. At priority 6 on the main loop's core, a few seconds of that is enough for the 5 s task watchdog. I haven't confirmed which branch the task was looping in.

An earlier variant on the same device (v0.7.0 of my firmware, stacks in PSRAM, 160 MHz) crashed the same way but with the PC in the protocol task's decryption during buffer refills; moving stacks to internal RAM and going to 240 MHz made that one go away.

https://github.com/esphome/esphome/issues/18789 looks like the same pattern on the same board (FLAC decode inside the sync task, task wdt, after Lost sync warnings on weak Wi-Fi).

#198 (in 0.9.4+) changes how the hard sync is measured after the sink starves; I have not tested whether it avoids the long late-drop run.

Possible fixes

  • Block briefly (e.g. vTaskDelay(1); std::this_thread::yield() doesn't help lower-priority tasks) after N inner-loop passes that didn't block, so the main loop gets CPU while a backlog is worked off.
  • Check whether #198's floored estimate also lets the load-time skip in decode_chunk() discard the post-stall backlog without decoding it (the PR deliberately keeps the unfloored estimate there).
  • Make the sync task priority configurable from ESPHome, or run it below the main loop when the core is shared.

Happy to test a build. This report was put together with the help of an AI assistant (Claude); the logs and backtrace are from the device.

主要言語
C++
スター
32
フォーク
19
平均マージ
14時間 54分
マージ済み PR(30日)
49

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Sendspin/sendspin-cpp のほかの issue

Sendspin/sendspin-cpp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。