Repository navigation
Conversation
salt-run installs a SIGINT handler that raises SystemExit, which escaped the state.event loop mid-poll and was reported by the runner as an exception with a traceback. Catch KeyboardInterrupt/SystemExit around the loop so the command stops quietly; the event bus is still closed by the with block. Fixes saltstack#59618 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
salt-run state.event(andsalt-call state.event) printed a traceback and reported the runner as failed when stopped with Ctrl+C.salt-runinstalls a SIGINT handler (salt/scripts.py::_handle_signals) that callssys.exit(). ThatSystemExitis raised whilestate.eventis blocked insidesevent.get_event(), in the tornado/asyncio selector poll. Nothing in the loop caught it, so it propagated up tosalt.client.mixins.low, which reportedException occurred in runner state.event: Traceback ... SystemExit: 0withretcode: 1.This wraps the loop in
try/except (KeyboardInterrupt, SystemExit)so the command stops quietly. The event bus is still closed by the surroundingwith get_event(...)block.What issues does this PR fix or reference?
Fixes #59618
Previous Behavior
Pressing Ctrl+C during
salt-run state.event pretty=TrueprintedExiting gracefully on Ctrl-cfollowed by a traceback ending inSystemExit: 0, and the runner returnedsuccess: False, retcode: 1.New Behavior
Ctrl+C prints only
Exiting gracefully on Ctrl-cand the command ends without a traceback.count=Nand event printing are unchanged.Merge requirements satisfied?
changelog/59618.fixed.mdtest_event_exits_cleanly_on_interrupt(parametrized overKeyboardInterruptandSystemExit)Testing
Unit tests (repo
.venv, Python 3.14):KeyboardInterruptcase escapesstate.eventand aborts the pytest session.3 passed(existingtest_eventplus both new cases).Before:
Real master (master, Salt 3008.4, Python 3.11, minion connected):
Exception occurred in runnerSystemExit: 0,retcode: 1salt/modules/state.py)Exiting gracefully on Ctrl-c(
timeoutexit code 124 is expected in both cases.)Regression check on the same master:
The listener printed
test/tag {"a": 1, "_stamp": ...}and exited on its own.Note:
lint-salt,lint-testsandcheck-changelog-entriespre-commit hooks were skipped locally because of local environment problems (unresolvable pinned requirement, no py3.15 changelog lock). Please rely on CI for those.