Skip to content

Remove GC-time __del__ cleanup: require explicit close / context manager - #70122

Open
dwoz wants to merge 3 commits into
saltstack:masterfrom
dwoz:dwoz/feat/remove-del-cleanup-explicit-close
Open

Remove GC-time __del__ cleanup: require explicit close / context manager#70122
dwoz wants to merge 3 commits into
saltstack:masterfrom
dwoz:dwoz/feat/remove-del-cleanup-explicit-close

Conversation

@dwoz

@dwoz dwoz commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Companion to LTS PR #70100. Same warning-routing change (route
unclosed-resource ResourceWarning finalizers through Salt's logger
via new salt.utils.resource_warnings.warn_until_close), but on
master (Potassium) the GC-time __del__ cleanup fallback is
not restored. Callers must use a context manager or explicit
.destroy() / .close() on salt.utils.event.SaltEvent,
salt.utils.asynchronous.SyncWrapper, salt.minion.MasterMinion,
salt.runner.RunnerClient and salt.wheel.WheelClient.

Missing-close sites are surfaced by a ResourceWarning and a
WARNING-level Salt log record, so leaks show up in operator logs at the
default log level instead of being silenced by Python's default
ResourceWarning filter.

Also fixes four warnings.warn sites in tcp.py / ws.py where
a missing f prefix rendered {self!r} as a literal.

The LTS branch (#70100, base 3008.x) restores the destroy()
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.py passes locally
  • Full test:full CI run green
  • Manual: fire-and-forget get_master_event(...).fire_event(...)
    loop shows the WARNING-level log record instead of silent socket
    leaks

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.
@dwoz
dwoz requested a review from a team as a code owner August 22, 2026 22:47
@dwoz dwoz added the test:full Run the full test suite label Aug 22, 2026
@dwoz dwoz added this to the Potassium v3009.0 milestone Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant