Task watchdog on ESP32 after a long receive stall: sync task starves the main loop while catching up
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- cpp
- Lĩnh vực
- audio-video-rtc, embedded-iot
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C++
- Star
- 32
- Fork
- 19
- Merge trung bình
- 14 giờ 54 phút
- Pull request đã merge (30 ngày)
- 49
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Sendspin/sendspin-cpp
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
Sendspin/sendspin-cpp#257 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
Sendspin/sendspin-cpp#219 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support clearing external buffersCó thể làm lại được @kahrendt đã nhận 120 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Sendspin/sendspin-cpp#55 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Sendspin/sendspin-cpp
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug test
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OpenAssetIO/OpenAssetIO#1527 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
ROCm/rocm-systems#15475 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
pocoproject/poco#5664 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Rename "Receipt" to "Recipe"Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100