Fix Windows server shutdown after 60s from ffmpeg cleanup (#605)

On Windows, process.terminate() on ffmpeg broadcasts CTRL_C_EVENT to
  the entire process group, causing uvicorn to shut down. Spawn ffmpeg
  with CREATE_NEW_PROCESS_GROUP so cleanup doesn't affect the server.
This commit is contained in:
maziggy
2026-03-04 15:25:55 +01:00
parent dba43530cb
commit 5ee2ef8dbf
2 changed files with 12 additions and 0 deletions
+3
View File
@@ -4,6 +4,9 @@ All notable changes to Bambuddy will be documented in this file.
## [0.2.2b2] - Unreleased
### Fixed
- **Windows: Server Shuts Down After 60 Seconds** ([#605](https://github.com/maziggy/bambuddy/issues/605)) — On Windows, terminating orphaned ffmpeg camera processes broadcast `CTRL_C_EVENT` to the entire process group, causing uvicorn to interpret it as a user-initiated shutdown. ffmpeg is now spawned in its own process group (`CREATE_NEW_PROCESS_GROUP`) so cleanup no longer affects the server. Reported by @Reactantvr.
## [0.2.2b1] - 2026-03-03
### Improved
+9
View File
@@ -2,6 +2,8 @@
import asyncio
import logging
import subprocess
import sys
from collections.abc import AsyncGenerator
from fastapi import APIRouter, Depends, HTTPException, Request
@@ -223,10 +225,17 @@ async def generate_rtsp_mjpeg_stream(
process = None
try:
# On Windows, spawn ffmpeg in its own process group so that
# terminate() doesn't broadcast CTRL_C_EVENT to uvicorn (#605).
kwargs: dict = {}
if sys.platform == "win32":
kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP
process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
**kwargs,
)
# Track active process for cleanup