Fix IOBuf memory leak in PythonUserException exception path#9738
Open
banitag1 wants to merge 1 commit intofacebook:masterfrom
Open
Fix IOBuf memory leak in PythonUserException exception path#9738banitag1 wants to merge 1 commit intofacebook:masterfrom
banitag1 wants to merge 1 commit intofacebook:masterfrom
Conversation
Summary: CONTEXT: When a thrift-python service handler raises a user-defined exception, the exception path serializes the response into an IOBuf and wraps it in a PythonUserException. This IOBuf was being leaked on every exception. WHAT: Two issues combined to cause the leak: 1. PythonUserException defines an explicit copy constructor (which clones the IOBuf) but no move constructor, suppressing implicit move generation. This caused cmove() to fall back to copying, cloning the IOBuf unnecessarily. 2. The pattern `_cpp_obj.release()` in serverCallback_coro returned a raw pointer that was never deleted. After the copy (not move) into the promise, the original object (including its cloned IOBuf) was leaked. Fix: Add defaulted move constructor/assignment to PythonUserException, and replace the release() pattern with a cdef helper that moves the unique_ptr into a local variable whose destructor properly cleans up. Differential Revision: D96219777
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:
CONTEXT: When a thrift-python service handler raises a user-defined exception,
the exception path serializes the response into an IOBuf and wraps it in a
PythonUserException. This IOBuf was being leaked on every exception.
WHAT: Two issues combined to cause the leak:
PythonUserException defines an explicit copy constructor (which clones the
IOBuf) but no move constructor, suppressing implicit move generation. This
caused cmove() to fall back to copying, cloning the IOBuf unnecessarily.
The pattern
_cpp_obj.release()in serverCallback_coro returned a rawpointer that was never deleted. After the copy (not move) into the promise,
the original object (including its cloned IOBuf) was leaked.
Fix: Add defaulted move constructor/assignment to PythonUserException, and
replace the release() pattern with a cdef helper that moves the unique_ptr
into a local variable whose destructor properly cleans up.
Differential Revision: D96219777