Destroy Runner/MasterMinion resources in salt-run and fix MasterMinion.__del__ - #70177
Open
twangboy wants to merge 5 commits into
Open
Destroy Runner/MasterMinion resources in salt-run and fix MasterMinion.__del__#70177twangboy wants to merge 5 commits into
twangboy wants to merge 5 commits into
Conversation
twangboy
added a commit
to twangboy/salt
that referenced
this pull request
Aug 28, 2026
pylint's blacklisted-module check (saltpylint) flags direct use of unittest.mock; Salt's own tests must import MagicMock from tests.support.mock instead. Fixes the "Lint Salt's Test Suite" CI failure on PR saltstack#70177.
dwoz
requested changes
Aug 30, 2026
…n.__del__
salt-run left its Runner un-destroy()'d, and RunnerClient/WheelClient
never cleaned up the MasterMinion they lazily create via
SyncClientMixin.mminion. Both were only reclaimed by __del__'s
GC-time safety net, which now logs a loud "unclosed Runner"/
"unclosed MasterMinion" WARNING on every salt-run invocation instead
of being silently filtered.
- salt/cli/run.py: wrap SaltRun.run() in try/finally so runner.destroy()
always runs, covering both the --doc early-exit and the normal path.
- salt/runner.py, salt/wheel/__init__.py: destroy() now also tears down
self._mminion.
- salt/minion.py: MasterMinion.destroy() leaves returners/functions/utils
as {}, not None, but __del__'s "already torn down" check tested for
None specifically, so even a properly destroy()'d MasterMinion kept
tripping the warning. Check falsiness instead.
Fixes saltstack#70174
pylint's blacklisted-module check (saltpylint) flags direct use of unittest.mock; Salt's own tests must import MagicMock from tests.support.mock instead. Fixes the "Lint Salt's Test Suite" CI failure on PR saltstack#70177.
Review follow-up for saltstack#70177/saltstack#70174: MasterMinion.destroy(), RunnerClient.destroy(), and WheelClient.destroy() ran their per-component teardown steps back-to-back with no exception isolation. If any one component's .destroy() call raised, every later step -- including resetting the remaining attributes to {} and, in RunnerClient/WheelClient's case, tearing down the lazily created MasterMinion (self._mminion), the whole point of this fix -- was silently skipped, and the exception propagated out of destroy() itself. That's now unconditionally called from salt/cli/run.py's finally: runner.destroy(), so an exception there would replace SaltRun.run()'s real result/control flow with an unrelated destroy()-time traceback. Wrap each component's teardown call in its own try/except (mirroring the existing pattern in salt/utils/asynchronous.py's SyncWrapper.destroy()), and make each attribute reset unconditional, so one component failing can never block another's teardown, and destroy() itself can never raise.
Review follow-up for saltstack#70177: RunnerClient already gained __enter__/ __exit__ (calling destroy()) as part of this fix, so salt/cli/run.py can use `with salt.runner.Runner(self.config) as runner:` instead of a manual try/finally calling runner.destroy() directly.
twangboy
force-pushed
the
fix/70174/3008.x
branch
from
August 31, 2026 15:25
6b264b8 to
c7288fc
Compare
Contributor
Author
|
Done — pushed c7288fc. |
The context-manager refactor (c7288fc) changed salt/cli/run.py to `with salt.runner.Runner(self.config) as runner:` instead of a manual try/finally. The existing tests patched salt.runner.Runner to return a bare MagicMock(), which broke two ways: - MagicMock()'s auto-generated __enter__() returns a *different* mock than the one the test asserts against, so `runner` inside the with block was never the mocked instance -- runner.print_docs()/ runner.run() calls landed on the wrong mock, hence 'DID NOT RAISE SystemExit' / 'print_docs called 0 times' on every platform in CI. - Wiring __exit__ to call destroy() directly returned destroy()'s mock return value (truthy), which made the with statement treat the SystemExit raised inside the block as handled and swallow it. Add a _fake_runner() helper that wires __enter__ to return the mock itself and __exit__ to call destroy() while still returning None, mirroring RunnerClient.__enter__/__exit__ for real.
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-runleft its Runnerun-destroy()'d, andRunnerClient/WheelClientnever cleaned up theMasterMinionthey lazily create viaSyncClientMixin.mminion. Both were only reclaimed by__del__'s GC-time safety net, which now logs a loud "unclosed Runner"/ "unclosed MasterMinion" WARNING on everysalt-runinvocation instead of being silently filtered.salt/cli/run.py: wrapSaltRun.run()intry/finallysorunner.destroy()always runs, covering both the--docearly-exit and the normal path.salt/runner.py,salt/wheel/__init__.py:destroy()now also tears downself._mminion.salt/minion.py:MasterMinion.destroy()leaves returners/functions/utils as{}, notNone, but__del__'s "already torn down" check tested forNonespecifically, so even a properlydestroy()'d MasterMinion kept tripping the warning. Check falsiness instead.What issues does this PR fix or reference?
Fixes #70174
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes