Repository navigation
Wrap fire-and-forget SaltEvent in salt.utils.error.fire_exception - #70259
Merged
dwoz merged 1 commit intoSep 10, 2026
Merged
Conversation
…ltstack#70175) ``salt.utils.error.fire_exception`` -- called from ``salt/minion.py:_thread_return`` (unhandled-exception path) and from ``salt/metaproxy/{proxy,deltaproxy}.py`` -- constructed a bare ``salt.utils.event.SaltEvent``, called ``fire_event()`` on it, and dropped the reference. With no context manager and no explicit ``destroy()``, cleanup ran only when GC eventually invoked ``SaltEvent.__del__`` and each finalisation emitted the three-warning triad from the underlying transport chain: unclosed publish server <PublishServer ...> unclosed publisher client <_TCPPubServerPublisher ...> unclosed SyncWrapper for cls=<class '..._TCPPubServerPublisher'> Fix: wrap the ``SaltEvent`` in a ``with`` block so ``__exit__`` calls ``destroy()`` -> ``close_pub()`` / ``close_pull()`` -> ``SyncWrapper.close()`` synchronously, tearing down the ``_TCPPubServerPublisher`` chain in the same call. Companion to PR saltstack#70206 (shutdown-time ``MinionManager`` destroy chain) and the sibling per-job caller fixes on branches ``dwoz/fix/70175-pubserver-perjob-leak`` (server-side ``PubServer._discard_on_close`` fix) and ``dwoz/fix/70175-saltevent-caller-close`` (``salt.modules.event.fire_master`` and ``salt.modules.mine._mine_send``). This PR closes the receive-path leg: the ``fire_exception`` helper on the minion's job-error return path. Regression test --------------- New unit test ``test_fire_exception_context_managed_no_unclosed_warnings`` in ``tests/pytests/unit/utils/test_error.py`` runs ``salt.utils.error.fire_exception`` 50 times and asserts no ``unclosed publish server`` / ``unclosed publisher client`` / ``unclosed SyncWrapper`` warnings surface after ``gc.collect()``. Pre-patch (verified by ``git stash push salt/utils/error.py`` and re-running):: AssertionError: fire_exception leaked 75 unclosed-resource warnings across 50 iterations (expected 0). Sample warnings: - unclosed publisher client <_TCPPubServerPublisher ...> - unclosed publisher client <_TCPPubServerPublisher ...> ... Post-patch: PASSED (0 warnings across 50 iterations).
dwoz
force-pushed
the
dwoz/fix/70175-receive-path-saltevent
branch
from
September 10, 2026 08:20
4e56e91 to
ac99b39
Compare
2 of 3 tasks
This branch was previously 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.
Fixes #70175
salt.utils.error.fire_exception-- called fromsalt/minion.py:_thread_return(unhandled-exception path) and fromsalt/metaproxy/{proxy,deltaproxy}.py-- constructed a baresalt.utils.event.SaltEvent, calledfire_event()on it, and dropped the reference. With no context manager and no explicitdestroy(), cleanup ran only when GC eventually invokedSaltEvent.__del__and each finalisation emitted the three-warning triad from the underlying transport chain:Fix: wrap the
SaltEventin awithblock so__exit__callsdestroy()->close_pub()/close_pull()->SyncWrapper.close()synchronously, tearing down the_TCPPubServerPublisherchain in the same call.Companion to PR #70206 (shutdown-time
MinionManagerdestroy chain) and the sibling per-job caller fixes on branchesdwoz/fix/70175-pubserver-perjob-leak(server-sidePubServer._discard_on_closefix) anddwoz/fix/70175-saltevent-caller-close(salt.modules.event.fire_masterandsalt.modules.mine._mine_send). This PR closes the receive-path leg: thefire_exceptionhelper on the minion's job-error return path.Regression test
New unit test
test_fire_exception_context_managed_no_unclosed_warningsintests/pytests/unit/utils/test_error.pyrunssalt.utils.error.fire_exception50 times and asserts nounclosed publish server/unclosed publisher client/unclosed SyncWrapperwarnings surface aftergc.collect().Pre-patch (verified by
git stash push salt/utils/error.pyand re-running)::Post-patch: PASSED (0 warnings across 50 iterations).