Skip to content

[Bug]: Windows Portable server cleanly shuts down exactly 60 seconds after UI opens (ffmpeg cleanup triggers CTRL_C_EVENT) #605

@Reactantvr

Description

@Reactantvr

Bug Description

Environment:

  • OS: Windows 10
  • Version: v0.2.1.1 (Standalone / Portable version)

Description:
When running the Windows portable version of Bambuddy, the backend server initiates a graceful, unprompted shutdown exactly 60 seconds after opening the web UI.

The logs do not show a crash/traceback; instead, they show a standard termination signal being received right as the camera stream cleanup task is triggered:

INFO:     Shutting down
INFO:     connection closed
INFO:     Waiting for connections to close. (CTRL+C to force quit)
WARNING   [backend.app.api.routes.camera] Camera stream ended (no more data)
INFO      [backend.app.api.routes.camera] Terminating ffmpeg process for stream 1-d1449f59
...
INFO:     Finished server process

Root Cause & Diagnosis:
The issue stems from how Windows handles process termination compared to Linux.
When the UI is opened, ffmpeg is spawned to handle the camera stream. Exactly 60 seconds later, _camera_cleanup_loop() fires and attempts to clean up orphaned ffmpeg streams.
When Python attempts to .terminate() or .kill() the ffmpeg subprocess on Windows, the OS broadcasts a CTRL_C_EVENT to the entire process group. Uvicorn receives this signal, assumes the user pressed Ctrl+C in the console, and dutifully initiates a graceful shutdown of the entire Bambuddy backend.

Confirmed Workaround:
I tested this by modifying backend\app\main.py and adding a return to the top of the _camera_cleanup_loop (around line 2233) to prevent the cleanup from running.

async def _camera_cleanup_loop():
    return # Added this to bypass
    from backend.app.api.routes.camera import cleanup_orphaned_streams

With this change, the server survives past 60 seconds and remains stable indefinitely, confirming the cleanup task is the culprit.

Expected Behavior

The backend server should continue running indefinitely while the web UI is open. The background _camera_cleanup_loop() should quietly terminate orphaned ffmpeg processes without broadcasting a CTRL_C_EVENT to the parent Uvicorn process group that causes the app to quit.

Steps to Reproduce

  1. Launch the Bambuddy v0.2.1.1 standalone/portable backend natively on Windows.
  2. Bambuddy web UI in a browser is already open along with single camera stream.
  3. Leave the UI open and wait exactly 60 seconds.
  4. Observe the console output: the server intercepts a termination signal, successfully stops the camera stream, and cleanly shuts itself down.

Printer Model

H2C

Bambuddy Version

0.2.1.1

Printer Firmware Version

01.01.00.00

Installation Method

Manual (git clone)

Operating System

Windows

Relevant Logs / Support Package

Screenshots

No response

Additional Context

No response

Checklist

  • I have searched existing issues to ensure this bug hasn't already been reported
  • I am using the latest version of Bambuddy
  • My printer is set to LAN Only mode
  • My printer has Developer Mode enabled

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions