Repository navigation
Wrap fire-and-forget MinionEvent callers to close SaltEvent chain (#7… - #70258
Merged
dwoz merged 2 commits intoSep 10, 2026
Merged
Conversation
…ltstack#70175) ``salt.modules.event.fire_master`` and ``salt.modules.mine._mine_send`` constructed a temporary ``MinionEvent``, 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 finalization emitted the three-warning triad from the underlying transport chain: unclosed publish server <PublishServer ...> unclosed publisher client <_TCPPubServerPublisher ...> unclosed SyncWrapper for cls=<class '..._TCPPubServerPublisher'> Under mixed-job load on a 3008.x minion this surfaced as ~3 ResourceWarnings per job (issue saltstack#70175 reports 646 warnings across ~200 jobs). The FDs backing each unclosed publisher pinned an in-flight IPC socket + IOStream + Unpacker until GC ran, contributing to the RSS growth and unclosed-resource noise flagged in the issue. Fix: wrap the ``MinionEvent`` 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 PR on branch ``dwoz/fix/70175-pubserver-perjob-leak`` (server-side ``PubServer._discard_on_close`` fix). This PR closes the third leg: per-job caller-side leaks on the minion. Regression test --------------- New unit test ``test_fire_master_context_managed_no_unclosed_warnings`` in ``tests/pytests/unit/modules/test_event.py`` runs ``salt.modules.event.fire_master`` 50 times and asserts no ``unclosed publish server`` / ``unclosed publisher client`` / ``unclosed SyncWrapper`` warnings are emitted. Pre-patch (verified by stashing this commit's changes to ``salt/modules/event.py`` + ``salt/modules/mine.py`` and re-running):: E AssertionError: fire_master leaked 74 unclosed-resource warnings E across 50 iterations (expected 0). Sample warnings: E - unclosed publisher client <_TCPPubServerPublisher ...> E - unclosed publish server <PublishServer ...> E - unclosed SyncWrapper for cls=<class '..._TCPPubServerPublisher'> FAILED tests/pytests/unit/modules/test_event.py::test_fire_master_context_managed_no_unclosed_warnings Post-patch: PASSED (0 warnings across 50 iterations).
twangboy
pushed a commit
to twangboy/salt
that referenced
this pull request
Sep 11, 2026
cli/daemons.py's Minion.start() never called shutdown()/destroy() when _real_start() raised SaltClientError because self.minion.restart was True -- it just returned (or looped for multi-master failover), leaving event_publisher/event to be reclaimed only by __del__'s GC-time safety net, which is what logged the loud "unclosed publish server", "unclosed SyncWrapper", and "unclosed publisher client" WARNING messages. - salt/cli/daemons.py: Minion.start() now destroys the MinionManager on SaltClientError, both before retrying (daemonized multi-master failover) and before falling through to the final break/return. The companion gap in MinionManager.destroy() itself -- it never closed event_publisher/event, only stop_async() (the SIGTERM path) did -- was independently fixed upstream in 3008.x by adbbb90 (PR saltstack#70258), so that half of the original fix is dropped here to avoid duplicating it. Fixes saltstack#70175
twangboy
added a commit
to twangboy/salt
that referenced
this pull request
Oct 1, 2026
Minion.start() never called destroy() when _real_start() raised SaltClientError because self.minion.restart was True, leaving event_publisher/event to be reclaimed only by __del__'s GC-time safety net. Destroy the MinionManager both before the daemonized multi-master failover retry and before the final return. The companion gap in MinionManager.destroy() was fixed in saltstack#70258. Refs saltstack#70175
2 of 3 tasks
twangboy
added a commit
to twangboy/salt
that referenced
this pull request
Oct 19, 2026
Minion.start() never called destroy() when _real_start() raised SaltClientError because self.minion.restart was True, leaving event_publisher/event to be reclaimed only by __del__'s GC-time safety net. Destroy the MinionManager both before the daemonized multi-master failover retry and before the final return. The companion gap in MinionManager.destroy() was fixed in saltstack#70258. Refs saltstack#70175
dwoz
pushed a commit
that referenced
this pull request
Oct 21, 2026
Minion.start() never called destroy() when _real_start() raised SaltClientError because self.minion.restart was True, leaving event_publisher/event to be reclaimed only by __del__'s GC-time safety net. Destroy the MinionManager both before the daemonized multi-master failover retry and before the final return. The companion gap in MinionManager.destroy() was fixed in #70258. Refs #70175
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.
…0175)
salt.modules.event.fire_masterandsalt.modules.mine._mine_sendconstructed a temporaryMinionEvent, 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 finalization emitted the three-warning triad from the underlying transport chain:Under mixed-job load on a 3008.x minion this surfaced as ~3 ResourceWarnings per job (issue #70175 reports 646 warnings across ~200 jobs). The FDs backing each unclosed publisher pinned an in-flight IPC socket + IOStream + Unpacker until GC ran, contributing to the RSS growth and unclosed-resource noise flagged in the issue.
Fix: wrap the
MinionEventin awithblock so__exit__callsdestroy()->close_pub()/close_pull()->SyncWrapper.close()synchronously, tearing down the_TCPPubServerPublisherchain in the same call. Companion to PR #70206 (shutdown-timeMinionManagerdestroy chain) and the sibling PR on branchdwoz/fix/70175-pubserver-perjob-leak(server-sidePubServer._discard_on_closefix). This PR closes the third leg: per-job caller-side leaks on the minion.Regression test
New unit test
test_fire_master_context_managed_no_unclosed_warningsintests/pytests/unit/modules/test_event.pyrunssalt.modules.event.fire_master50 times and asserts nounclosed publish server/unclosed publisher client/unclosed SyncWrapperwarnings are emitted.Pre-patch (verified by stashing this commit's changes to
salt/modules/event.py+salt/modules/mine.pyand re-running)::Post-patch: PASSED (0 warnings across 50 iterations).
What does this PR do?
What issues does this PR fix or reference?
Fixes
Previous Behavior
Remove this section if not relevant
New Behavior
Remove this section if not relevant
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes/No