[pulsar-client-cpp] Fix memory leak caused by not being executed ClientConnection destructor - #5286
Merged
Merged
Conversation
Contributor
Author
|
rerun cpp tests |
Contributor
Author
|
rerun java8 tests |
merlimat
approved these changes
Sep 29, 2019
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.
Motivation
Currently, closing a C++ Pulsar client object does not execute the destructor for the generated
ClientConnectionobject. As a result, memory usage increases in applications that repeatedly create and close clients.This pull-request is a continuation of #5246.
Modifications
The reason why the
ClientConnectiondestructor is not executed is that the reference count of the shared pointer does not become 0 even when theClientConnectionobject is closed. As a result of the investigation, it was found that if the shared pointerexecutor_held by theClientConnectionobject is reset, the reference count becomes 0 and the destructor is executed.However, with this fix alone, executing the following code causes an "Illegal instruction" error and the program crashes.
https://gist.github.com/massakam/ebd169caff3db802eee5001b0d06c980
The exact cause is unknown, but this issue doesn't seem to occur if closing
ClientConnectionbefore closingExecutorServiceProvider. So, I changed theConnectionPooldestructor added in #5246 to theclose()method and call it before closingExecutorServiceProvider.