Fix HighState/State leaking fileclient on init failure (#69637)#69675
Merged
Conversation
When ``HighState.__init__`` or ``State.__init__`` raised after allocating their fileclient (e.g. ``BaseHighState.__init__`` failing during ``master_opts()``, or ``_gather_pillar()`` failing during pillar compilation), the caller never received the instance and therefore never called ``.destroy()``. The fileclient's ZeroMQ ``RequestClient`` was finalized during garbage collection with ``_closing = False``, tripping the ``TransportWarning: Unclosed transport!`` warning that PR saltstack#65559 added. Wrap both constructors' post-allocation bodies in ``try/except`` that destroys the freshly-allocated fileclient before re-raising. Also close the temporary ``Pillar`` object built by ``State._gather_pillar()`` in a ``try/finally`` so its channel doesn't rely on ``__del__`` ordering at shutdown. Fixes saltstack#69637
twangboy
approved these changes
Jul 6, 2026
dwoz
added a commit
that referenced
this pull request
Jul 23, 2026
When HighState.__init__ or State.__init__ raised after allocating their fileclient (e.g. BaseHighState.__init__ failing during master_opts(), or _gather_pillar() failing during pillar compilation), the caller never received the instance and therefore never called .destroy(). The fileclient's ZeroMQ RequestClient was finalized during garbage collection with _closing = False, tripping the ``TransportWarning: Unclosed transport!`` warning that PR #65559 added. Wrap both constructors' post-allocation bodies in try/except that destroys the freshly-allocated fileclient before re-raising. Also close the temporary Pillar object built by State._gather_pillar() in a try/finally so its channel doesn't rely on __del__ ordering at shutdown. Backport of cb09894 from PR #69675.
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?
Fix
HighState.__init__andState.__init__leaking their fileclient (and its ZeroMQ transport) when a later step in the constructor raises. The salt-call flow that hits the failure now shuts down cleanly instead of emittingTransportWarning: Unclosed transport!at interpreter exit.What issues does this PR fix or reference?
Fixes #69637
Previous Behavior
salt-call state.applyon 3006.26/3006.27 prints repeatedTransportWarning: Unclosed transport! <salt.transport.zeromq.RequestClient>messages, with a stack pointing atHighState.__init__->get_file_client->RemoteClient.__init__. This is the warning added by PR #65559.New Behavior
Both
HighState.__init__andState.__init__wrap their post-get_file_clientbodies intry/exceptand call.destroy()on the freshly-allocated fileclient before re-raising, so the ZeroMQ transport is torn down cleanly andTransport.__del__no longer trips the warning.State._gather_pillar()also destroys the temporaryPillarin atry/finallyso its channel doesn't rely on__del__ordering at shutdown.Merge requirements satisfied?
changelog/69637.fixed.md)tests/pytests/unit/state/test_highstate_transport_cleanup.py)Commits signed with GPG?
Yes