resource_warnings: route unclosed-resource warnings through Salt logger - #70100
Merged
dwoz merged 2 commits intoAug 25, 2026
Merged
Conversation
dwoz
force-pushed
the
dwoz/fix/log-unclosed-resource-warnings-3008x
branch
from
August 20, 2026 22:22
f97dc11 to
1382857
Compare
dwoz
force-pushed
the
dwoz/fix/log-unclosed-resource-warnings-3008x
branch
from
August 20, 2026 22:22
1382857 to
73e2ffd
Compare
On this LTS branch, restore the GC-time destroy() fallback in salt.minion.MasterMinion, salt.runner.RunnerClient, salt.wheel.WheelClient and salt.utils.event.SaltEvent that commit 0c3f53d ("Remove __del__ methods from leak fixes") had removed. The warn_until_close call added in this PR still runs first inside each __del__, so the missing-close() contract is now visible via a WARNING-level log record AND the underlying resource is still cleaned up -- callers that historically relied on GC-time cleanup (e.g. sseape's fire-and-forget get_master_event(...).fire_event(...)) do not silently leak sockets while migrating to explicit destroy() / context-manager use. The companion change on master (Potassium) drops the destroy() fallback and requires callers to be explicit; the WARNING here is the migration signal for that upcoming behavior change.
twangboy
approved these changes
Aug 25, 2026
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.
Summary
Python filters
ResourceWarningby default, so a barewarnings.warn(..., ResourceWarning)from a__del__finalizer is silently dropped in production. Callers that missed aclose()/destroy()/ context-manager contract therefore never see the intended migration signal, and the leaked resource accumulates invisibly.Concrete incident that motivated this
After commit
0c3f53d9172removed the__del__-based cleanup fromSaltEvent/MasterMinion/RunnerClient/WheelClientin favor of aResourceWarning-emitting__del__, out-of-tree consumers like SSEAPE that relied on GC-time cleanup via the inline patternbegan leaking one unix socket per fire-and-forget instance on 3008.2+. In a VMSP master pod the leak accumulated ~350 sockets/min → +180 MB of kernel slab per hour → OOM every ~78 min at the 1 GiB pod cap. The intended
ResourceWarningnever reached operator logs becauseResourceWarningis silenced by default in production Python and Salt didn't route it through logging.What this PR does
salt.utils.resource_warnings.warn_until_close(message, source, category=ResourceWarning, log=None):ResourceWarning(behavior preserved for dev / test /-W default::ResourceWarning).warnings.warnand the logger call are wrapped so interpreter-shutdown races don't propagate.salt/utils/event.py(SaltEvent)salt/utils/asynchronous.py(SyncWrapper)salt/transport/tcp.py(Subscriber, TCPPuller, PubServer, _TCPPubServerPublisher)salt/transport/ws.py(PublishClient x2)import warningsfrom the 4 files above.warnings.warnsites (bothws.pysites plus twotcp.pysites) had a missingfprefix, so{self!r}was printed as the literal string instead of interpolating. Fixed as part of the migration.Test plan
tests/pytests/unit/utils/test_resource_warnings.pycover:ResourceWarningAND a WARNING log recordlogpassedwarnings.warnraising (interpreter-shutdown safety)DeprecationWarning)