refactor: improve stream cleanup before system reboot by closing WebRTC connections and stopping multicasters

This commit is contained in:
pstruebi
2025-09-26 13:50:14 +02:00
parent 8f9390ae50
commit 464bb6fe86
+15 -3
View File
@@ -594,11 +594,23 @@ async def system_reboot():
Requires the service user to have passwordless sudo permissions to run 'reboot'.
"""
try:
# Best-effort: stop any active streaming cleanly
# Best-effort: stop any active streaming cleanly WITHOUT persisting state
try:
await stop_audio()
# Close any WebRTC peer connections
close_tasks = [pc.close() for pc in list(pcs)]
pcs.clear()
if close_tasks:
await asyncio.gather(*close_tasks, return_exceptions=True)
# Stop streaming on multicasters but DO NOT touch stream_settings.json
if multicaster1 is not None:
await multicaster1.stop_streaming()
await multicaster1.shutdown()
if multicaster2 is not None:
await multicaster2.stop_streaming()
await multicaster2.shutdown()
except Exception:
log.warning("Failed to stop audio before reboot", exc_info=True)
log.warning("Non-fatal: failed to stop streams before reboot", exc_info=True)
# Launch reboot without waiting for completion
try: