saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.2k stars 5.48k forks source link

[BUG] Remove __del__ usage from the codebase #57793

Open s0undt3ch opened 4 years ago

s0undt3ch commented 4 years ago

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

s0undt3ch commented 4 years ago

Might be somewhat related to termination hanging seen in https://github.com/saltstack/salt/issues/57574

s0undt3ch commented 3 years ago

Moved to Silicon