saltstack / saltstack/salt

[BUG] Remove __del__ usage from the codebase

Open
#57,793 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity-high
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
Remove ALL occurrences of __del__ usage.

Relying on this functionality can actually prevent objects from being GC'ed.

Instead, and if we really need a termination routine, we should implement the context manager protocol by adding __enter__ and __exit__ and using the class in a with statement.

Expected behavior
All classes which require explicit termination routines should implement and use the context manager protocol.

Additional context
A few examples of offending code:

https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/utils/rsax931.py#L157
https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/utils/rsax931.py#L203
https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/transport/ipc.py#L239
https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/transport/ipc.py#L362
https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/transport/ipc.py#L602
https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/transport/ipc.py#L767
https://github.com/saltstack/salt/blob/b95213ec903402f25c1e0aeb3990fe8452ab63ce/salt/transport/tcp.py#L195

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with a repository-wide search for __del__, then inspect the examples in salt/utils/rsax931.py, salt/transport/ipc.py, and salt/transport/tcp.py to understand each object's cleanup path. Identify the affected lifecycle callers and verify that explicit termination uses the stated context-manager approach; done means no __del__ occurrences remain and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.