Fix signal handler cleanup bug when startup fails early #45

Closed
opened 2026-05-12 00:48:54 -04:00 by JackFrostbyte · 0 comments

Context

A review found a real runtime bug in runtime.py.

previous_sigterm_handler can be referenced in the finally block before it is assigned. If startup fails before the signal handler is registered — for example OpenRGB unreachable, device mapping mismatch, or runtime zone validation failure — the cleanup path can raise UnboundLocalError.

That masks the original exception and makes troubleshooting harder.

Scope

  • Initialize previous_sigterm_handler = None before the try block.
  • Make the finally cleanup safe when startup fails before signal registration.
  • Preserve the original startup exception in logs.
  • Add a regression test if practical.

Acceptance criteria

  • Startup failures no longer trigger UnboundLocalError.
  • The real original exception remains visible.
  • Existing SIGTERM cleanup behavior still works.
  • ruff format passes.
  • ruff check passes.
  • Tests pass.

Branch workflow

Base branch:

develop

Suggested work branch:

fix/issue-45-signal-handler-startup-failure

Pull request target:

develop

Do not merge directly into main. main should only receive tested release-ready changes from develop.

## Context A review found a real runtime bug in `runtime.py`. `previous_sigterm_handler` can be referenced in the `finally` block before it is assigned. If startup fails before the signal handler is registered — for example OpenRGB unreachable, device mapping mismatch, or runtime zone validation failure — the cleanup path can raise `UnboundLocalError`. That masks the original exception and makes troubleshooting harder. ## Scope - Initialize `previous_sigterm_handler = None` before the `try` block. - Make the `finally` cleanup safe when startup fails before signal registration. - Preserve the original startup exception in logs. - Add a regression test if practical. ## Acceptance criteria - Startup failures no longer trigger `UnboundLocalError`. - The real original exception remains visible. - Existing SIGTERM cleanup behavior still works. - `ruff format` passes. - `ruff check` passes. - Tests pass. ## Branch workflow Base branch: `develop` Suggested work branch: `fix/issue-45-signal-handler-startup-failure` Pull request target: `develop` Do not merge directly into `main`. `main` should only receive tested release-ready changes from `develop`.
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JackFrostbyte/rgb-aura#45
No description provided.