-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[3006.x] Fix msgpack leak in tcp.py #68399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3006.x
Are you sure you want to change the base?
Conversation
Author: tcarroll25 saltstack#67931 (comment)
|
We do not need #68394. These changes will get merged forward. |
|
How does this prevent a leak? A method scoped variable is now being assigned to the object? Shouldn't the variable get cleaned up once it leaves scope? Even if it's doesn't, surely just assign "unpacker = None" inside the catch block would do the same? What am I missing? |
|
@tcarroll25 can you explain your change? |
To give a quick summary of the situation: In Python, memory leaks related to exception handling occur when a persistent reference to an exception object is held, preventing the garbage collector from cleaning it up. The danger lies in the fact that an exception's traceback object contains a complete stack frame, which can hold references to all local variables within that scope, including very large data structures. When an exception is raised, the Python interpreter bundles the exception object with a traceback object that contains the state of the call stack. The traceback keeps references to the stack frames, and each stack frame holds references to its local variables. A memory leak occurs if your code creates a cycle by holding a reference to the exception or traceback object in a way that prevents the garbage collector from deleting it. In this case the local Here is the end of the trace showing the exact location of the leak in Here is the memory with the fix after running I tried various fixes but the only one to work was making a member variable out of the I noticed that other places in the salt When triaging this bug I noticed that someone else from my organization had actually patched this memory leak years ago by setting |
@OrangeDog thanks for opening this PR! I've been slammed with work the last few days and had not circled back to it yet. |
|
@tcarroll25 interesting... I'm nonexpert in Python cleanup, but it sounds like the exception object itself is being held onto and therefore Python can't clean it up. The only place Overall.. Seems weird. Edit: I just saw you also mentioned coroutines. Maybe, I've seen a number of dangling coroutines in Salt. |
I agree, it is a strange one. For one of my fix attempts I tried removing the log messages in each exception block because I thought the |
|
My assumption is leaking is related to the use |
|
I assume this change was tested in a production environment where a leak went away, is this correct? |
Yes that is correct. I can usually reproduce the leak in a few minutes and I ran it for over a day and saw no memory leak. |
Backport #68394