Leave voice before closing the server on shutdown

AlreadyConnected kept coming back after every rebuild. Shutdown closed
the HTTP server first, which blocks while the panel's WebSocket is open,
so Docker's grace period ran out and the process was killed before it
ever left the voice channels — and Stoat only clears a bot's voice state
when it disconnects, leaving the stale entry that refuses the next join.

Voice channels are now left first, and each shutdown step has its own
deadline so neither can eat the grace period.

A failed join_call also escaped as an unhandled rejection with a full
stack, because revoice awaits it inside an async executor it never
guards; the error is already latched and reported, so that call no longer
settles at all.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-09-09 02:44:36 +03:00
co-authored by Claude Opus 5
parent 224d5679a3
commit c7f2080604
3 changed files with 33 additions and 10 deletions
+8 -2
View File
@@ -164,8 +164,14 @@ cd /opt/stoat-mbot && docker compose up -d --build && docker compose logs -f
docker compose exec redis valkey-cli SREM 'vc_members:<ID_голосового_канала>' '<ID_бота>'
```
В норме состояние снимает `voice-ingress` по вебхуку от LiveKit — если ситуация повторяется
после каждого перезапуска, смотрите `docker compose logs voice-ingress`.
Решает дело именно `DEL vc:<ID_бота>` — он должен вернуть `(integer) 1`. `SREM` часто
возвращает `0`, это нормально: участники там хранятся в другом виде.
Само состояние снимает Stoat, когда бот отключается от LiveKit, поэтому важно, чтобы бот
успевал корректно выйти при остановке контейнера — он выходит из каналов первым делом, с
отдельным лимитом времени. Если проблема всё же повторяется после каждого перезапуска,
смотрите `docker compose logs voice-ingress`: снимать состояние по вебхуку от LiveKit —
его работа.
4. **Бот в канале, но звука нет.** Это уже медиа-трафик: LiveKit анонсирует клиентам свой адрес
из `rtc.node_ip` / `use_external_ip` в `/opt/stoat/livekit.yml` и ждёт UDP на 50000-50100.
Если анонсируется внешний IP, а роутер не умеет NAT loopback, пакеты от контейнера до него не