Task watchdog on ESP32 after a long receive stall: sync task starves the main loop while catching up
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Sendspin/sendspin-cpp のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
Sendspin/sendspin-cpp#257 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
Sendspin/sendspin-cpp#219 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
Support clearing external buffers再び着手できるかも @kahrendt が 120 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
Sendspin/sendspin-cpp#55 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
Sendspin/sendspin-cpp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
ROCm/rocm-systems#15475 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
pocoproject/poco#5664 ·
メンテナーはふだん 2 日以内に返信
-
community:good-first-issue kind:bug kind:test scope:control status:needs-triage vehicle:rover
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
PX4/PX4-Autopilot#29727 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
better error message error not reported I/O ICE low priority semantics
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信