fix(signals): narrow cleanup except to Exception (S5754) #77
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Claude/backup-script:fix/issue-31-S5754-signals-bare-except"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #31
Problem
SonarQube rule S5754 flags the
except BaseException as e:atcore/signals.py:101(insideSignalManager._run_one) for swallowingevery exception class —
SystemExit,KeyboardInterrupt, the lot —without reraising. In practice the second-signal escalation path in
_handlecallsos._exitand never raises, so the bug is latent today;but if any registered cleanup callback ever raises
SystemExit/KeyboardInterrupt(directly or via a library that does), the LIFO drainchain would silently log it as
signals.cleanup.failedand march on, indefiance of the user's clear intent to exit.
Fix
Narrow the offending
excepttoException. Behaviour for normal cleanupbugs is unchanged (logged and swallowed, drain continues — rule #1 in
CLAUDE.md, "DockerStop's restart guarantee"). Behaviour for genuine
control-flow exits is restored:
SystemExit/KeyboardInterruptpropagate out of
_run_one, unwind out of_drain, and reach the caller.Inline comment documents the rationale matching the convention used in
core/executor.py.Verification
pytest -q tests/unit/— all 211 tests pass, includingtests/unit/test_signals_reentrant.py.pytest -q tests/integration/test_signal_manager.py— all 7 testspass, including the swallow-cleanup-error and LIFO-drain regression
cases.
mypy --strict src/gardien/core/— clean (10 source files, no issues).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.