Remove GC-time __del__ cleanup: require explicit close / context manager - #70122
Open
dwoz wants to merge 3 commits into
Open
Remove GC-time __del__ cleanup: require explicit close / context manager#70122dwoz wants to merge 3 commits into
dwoz wants to merge 3 commits into
Conversation
Route unclosed-resource ResourceWarning finalizers through Salt's logger in addition to Python's warnings module (same warning-routing change as companion LTS PR saltstack#70100), but unlike the LTS PR do NOT add or restore a destroy() / close() fallback inside __del__. Callers must now use a context manager or explicit destroy() / close() on: - salt.utils.event.SaltEvent - salt.utils.asynchronous.SyncWrapper - salt.minion.MasterMinion (already lacks __del__ since 0c3f53d) - salt.runner.RunnerClient (already lacks __del__ since 0c3f53d) - salt.wheel.WheelClient (already lacks __del__ since 0c3f53d) Missing-close sites are surfaced by a ResourceWarning AND a WARNING-level Salt log record via salt.utils.resource_warnings.warn_until_close, so leaks show up in operator logs at the default log level instead of being silenced by Python's default ResourceWarning filter. This gives out-of- tree consumers a full major-release window (Potassium) to migrate off GC-time cleanup before the fallback disappears here. Also fixes four warnings.warn sites in tcp.py / ws.py where a missing f prefix rendered {self!r} as a literal instead of interpolating. Companion to LTS PR saltstack#70100 which keeps the destroy() fallback alongside the loud warning.
3 tasks
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
Companion to LTS PR #70100. Same warning-routing change (route
unclosed-resource
ResourceWarningfinalizers through Salt's loggervia new
salt.utils.resource_warnings.warn_until_close), but onmaster(Potassium) the GC-time__del__cleanup fallback isnot restored. Callers must use a context manager or explicit
.destroy()/.close()onsalt.utils.event.SaltEvent,salt.utils.asynchronous.SyncWrapper,salt.minion.MasterMinion,salt.runner.RunnerClientandsalt.wheel.WheelClient.Missing-close sites are surfaced by a
ResourceWarningand aWARNING-level Salt log record, so leaks show up in operator logs at the
default log level instead of being silenced by Python's default
ResourceWarningfilter.Also fixes four
warnings.warnsites intcp.py/ws.pywherea missing
fprefix rendered{self!r}as a literal.The LTS branch (#70100, base
3008.x) restores thedestroy()fallback alongside the loud warning so out-of-tree consumers (e.g.
sseape's fire-and-forget
get_master_event(...).fire_event(...))that historically relied on GC-time cleanup do not silently leak
sockets while migrating to explicit
.close()/ context-manager use.Test plan
tests/pytests/unit/utils/test_resource_warnings.pypasses locallytest:fullCI run greenget_master_event(...).fire_event(...)loop shows the WARNING-level log record instead of silent socket
leaks