-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
cpp: fix reference leak when reader create #7793
Merged
Merged
Conversation
This file contains 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
sijie
approved these changes
Aug 11, 2020
wolfstudy
pushed a commit
that referenced
this pull request
Aug 12, 2020
### Motivation User reports a valgrind error for `client::createReader` method: ``` ==23308== 284,826 (160 direct, 284,666 indirect) bytes in 1 blocks are definitely lost in loss record 113 of 113 ==23308== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344) ==23308== by 0x5303B4A: allocate (new_allocator.h:104) ==23308== by 0x5303B4A: allocate (alloc_traits.h:351) ==23308== by 0x5303B4A: __shared_count<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:499) ==23308== by 0x5303B4A: __shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:957) ==23308== by 0x5303B4A: shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:316) ==23308== by 0x5303B4A: allocate_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:598) ==23308== by 0x5303B4A: make_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader> > (shared_ptr.h:614) ==23308== by 0x5303B4A: Promise (Future.h:91) ==23308== by 0x5303B4A: pulsar::Client::createReader(std::string const&, pulsar::MessageId const&, pulsar::ReaderConfiguration const&, pulsar::Reader&) (Client.cc:142) ==23308== by 0x401DDB: main (pulsarReader.cpp:92) ==23308== ``` It seems the `ReaderImpl` has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue. ### Modifications - fix WaitForCallbackValue which is changed in PR #3484. - add test for the reference issue. ### Verifying this change ut passed. valgrind found no issue: ``` ==14758== LEAK SUMMARY: ==14758== definitely lost: 0 bytes in 0 blocks ==14758== indirectly lost: 0 bytes in 0 blocks ==14758== possibly lost: 0 bytes in 0 blocks ==14758== still reachable: 12,621 bytes in 145 blocks ==14758== suppressed: 0 bytes in 0 blocks ==14758== ==14758== For lists of detected and suppressed errors, rerun with: -s ==14758== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ``` (cherry picked from commit 0e67fc5)
huangdx0726
pushed a commit
to huangdx0726/pulsar
that referenced
this pull request
Aug 24, 2020
### Motivation User reports a valgrind error for `client::createReader` method: ``` ==23308== 284,826 (160 direct, 284,666 indirect) bytes in 1 blocks are definitely lost in loss record 113 of 113 ==23308== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344) ==23308== by 0x5303B4A: allocate (new_allocator.h:104) ==23308== by 0x5303B4A: allocate (alloc_traits.h:351) ==23308== by 0x5303B4A: __shared_count<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:499) ==23308== by 0x5303B4A: __shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:957) ==23308== by 0x5303B4A: shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:316) ==23308== by 0x5303B4A: allocate_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:598) ==23308== by 0x5303B4A: make_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader> > (shared_ptr.h:614) ==23308== by 0x5303B4A: Promise (Future.h:91) ==23308== by 0x5303B4A: pulsar::Client::createReader(std::string const&, pulsar::MessageId const&, pulsar::ReaderConfiguration const&, pulsar::Reader&) (Client.cc:142) ==23308== by 0x401DDB: main (pulsarReader.cpp:92) ==23308== ``` It seems the `ReaderImpl` has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue. ### Modifications - fix WaitForCallbackValue which is changed in PR apache#3484. - add test for the reference issue. ### Verifying this change ut passed. valgrind found no issue: ``` ==14758== LEAK SUMMARY: ==14758== definitely lost: 0 bytes in 0 blocks ==14758== indirectly lost: 0 bytes in 0 blocks ==14758== possibly lost: 0 bytes in 0 blocks ==14758== still reachable: 12,621 bytes in 145 blocks ==14758== suppressed: 0 bytes in 0 blocks ==14758== ==14758== For lists of detected and suppressed errors, rerun with: -s ==14758== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```
lbenc135
pushed a commit
to lbenc135/pulsar
that referenced
this pull request
Sep 5, 2020
### Motivation User reports a valgrind error for `client::createReader` method: ``` ==23308== 284,826 (160 direct, 284,666 indirect) bytes in 1 blocks are definitely lost in loss record 113 of 113 ==23308== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344) ==23308== by 0x5303B4A: allocate (new_allocator.h:104) ==23308== by 0x5303B4A: allocate (alloc_traits.h:351) ==23308== by 0x5303B4A: __shared_count<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:499) ==23308== by 0x5303B4A: __shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:957) ==23308== by 0x5303B4A: shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:316) ==23308== by 0x5303B4A: allocate_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:598) ==23308== by 0x5303B4A: make_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader> > (shared_ptr.h:614) ==23308== by 0x5303B4A: Promise (Future.h:91) ==23308== by 0x5303B4A: pulsar::Client::createReader(std::string const&, pulsar::MessageId const&, pulsar::ReaderConfiguration const&, pulsar::Reader&) (Client.cc:142) ==23308== by 0x401DDB: main (pulsarReader.cpp:92) ==23308== ``` It seems the `ReaderImpl` has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue. ### Modifications - fix WaitForCallbackValue which is changed in PR apache#3484. - add test for the reference issue. ### Verifying this change ut passed. valgrind found no issue: ``` ==14758== LEAK SUMMARY: ==14758== definitely lost: 0 bytes in 0 blocks ==14758== indirectly lost: 0 bytes in 0 blocks ==14758== possibly lost: 0 bytes in 0 blocks ==14758== still reachable: 12,621 bytes in 145 blocks ==14758== suppressed: 0 bytes in 0 blocks ==14758== ==14758== For lists of detected and suppressed errors, rerun with: -s ==14758== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```
lbenc135
pushed a commit
to lbenc135/pulsar
that referenced
this pull request
Sep 5, 2020
### Motivation User reports a valgrind error for `client::createReader` method: ``` ==23308== 284,826 (160 direct, 284,666 indirect) bytes in 1 blocks are definitely lost in loss record 113 of 113 ==23308== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344) ==23308== by 0x5303B4A: allocate (new_allocator.h:104) ==23308== by 0x5303B4A: allocate (alloc_traits.h:351) ==23308== by 0x5303B4A: __shared_count<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:499) ==23308== by 0x5303B4A: __shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:957) ==23308== by 0x5303B4A: shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:316) ==23308== by 0x5303B4A: allocate_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:598) ==23308== by 0x5303B4A: make_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader> > (shared_ptr.h:614) ==23308== by 0x5303B4A: Promise (Future.h:91) ==23308== by 0x5303B4A: pulsar::Client::createReader(std::string const&, pulsar::MessageId const&, pulsar::ReaderConfiguration const&, pulsar::Reader&) (Client.cc:142) ==23308== by 0x401DDB: main (pulsarReader.cpp:92) ==23308== ``` It seems the `ReaderImpl` has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue. ### Modifications - fix WaitForCallbackValue which is changed in PR apache#3484. - add test for the reference issue. ### Verifying this change ut passed. valgrind found no issue: ``` ==14758== LEAK SUMMARY: ==14758== definitely lost: 0 bytes in 0 blocks ==14758== indirectly lost: 0 bytes in 0 blocks ==14758== possibly lost: 0 bytes in 0 blocks ==14758== still reachable: 12,621 bytes in 145 blocks ==14758== suppressed: 0 bytes in 0 blocks ==14758== ==14758== For lists of detected and suppressed errors, rerun with: -s ==14758== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```
lbenc135
pushed a commit
to lbenc135/pulsar
that referenced
this pull request
Sep 5, 2020
### Motivation User reports a valgrind error for `client::createReader` method: ``` ==23308== 284,826 (160 direct, 284,666 indirect) bytes in 1 blocks are definitely lost in loss record 113 of 113 ==23308== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344) ==23308== by 0x5303B4A: allocate (new_allocator.h:104) ==23308== by 0x5303B4A: allocate (alloc_traits.h:351) ==23308== by 0x5303B4A: __shared_count<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:499) ==23308== by 0x5303B4A: __shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:957) ==23308== by 0x5303B4A: shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:316) ==23308== by 0x5303B4A: allocate_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:598) ==23308== by 0x5303B4A: make_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader> > (shared_ptr.h:614) ==23308== by 0x5303B4A: Promise (Future.h:91) ==23308== by 0x5303B4A: pulsar::Client::createReader(std::string const&, pulsar::MessageId const&, pulsar::ReaderConfiguration const&, pulsar::Reader&) (Client.cc:142) ==23308== by 0x401DDB: main (pulsarReader.cpp:92) ==23308== ``` It seems the `ReaderImpl` has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue. ### Modifications - fix WaitForCallbackValue which is changed in PR apache#3484. - add test for the reference issue. ### Verifying this change ut passed. valgrind found no issue: ``` ==14758== LEAK SUMMARY: ==14758== definitely lost: 0 bytes in 0 blocks ==14758== indirectly lost: 0 bytes in 0 blocks ==14758== possibly lost: 0 bytes in 0 blocks ==14758== still reachable: 12,621 bytes in 145 blocks ==14758== suppressed: 0 bytes in 0 blocks ==14758== ==14758== For lists of detected and suppressed errors, rerun with: -s ==14758== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```
BewareMyPower
added a commit
to BewareMyPower/pulsar
that referenced
this pull request
Mar 24, 2022
Fixes apache#14848 Fixes apache#14719 ### Motivation apache#7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. apache#14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0.
BewareMyPower
added a commit
to BewareMyPower/pulsar
that referenced
this pull request
Mar 31, 2022
Fixes apache#14848 Fixes apache#14719 ### Motivation apache#7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. apache#14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0.
BewareMyPower
added a commit
to BewareMyPower/pulsar
that referenced
this pull request
Apr 1, 2022
Fixes apache#14848 Fixes apache#14719 ### Motivation apache#7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. apache#14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0.
lhotari
pushed a commit
that referenced
this pull request
Apr 1, 2022
Fixes #14848 Fixes #14719 ### Motivation #7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. #14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0.
BewareMyPower
added a commit
that referenced
this pull request
Apr 2, 2022
Fixes #14848 Fixes #14719 ### Motivation #7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. #14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0. (cherry picked from commit f84ff57)
BewareMyPower
added a commit
that referenced
this pull request
Apr 2, 2022
Fixes #14848 Fixes #14719 ### Motivation #7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. #14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0. (cherry picked from commit f84ff57)
BewareMyPower
added a commit
that referenced
this pull request
Apr 2, 2022
Fixes #14848 Fixes #14719 ### Motivation #7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. #14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0. (cherry picked from commit f84ff57)
Nicklee007
pushed a commit
to Nicklee007/pulsar
that referenced
this pull request
Apr 20, 2022
Fixes apache#14848 Fixes apache#14719 ### Motivation apache#7793 introduced a `testReferenceLeak` to avoid cyclic referenece of the reader. However, it adds a unused field `readerImplWeakPtr_` only for tests. The access to this field is not thread safe that the write operation happens in `handleConsumerCreated` while the read operation can happen anywhere via the getter. So there is a little chance that `readerPtr` in `testReferenceLeak` doesn't point to the right object. In addition, we should only guarantee the reference count becomes 0 after the producer, consumer or reader goes out of its scope. apache#14797 adds a `ClientTest.testReferenceCount` but it's also flaky. It's caused by the shared pointer of `ProducerImpl` is published to another thread via `shared_from_this()` but the test has a strong expectation that the reference count is exactly 1. ### Modifications - Remove `readerImplWeakPtr_` from `ReaderImpl` and get the weak pointer from `Reader` directly by adding a method to `PulsarFriend`. - Add the check of reader's reference count to `testReferenceCount` and remove the redundant `testReferenceLeak`. - Instead of asserting the reference count of producer/consumer/reader is 1, just assume the it's greater than 0.
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
User reports a valgrind error for
client::createReader
method:It seems the
ReaderImpl
has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue.Modifications
Verifying this change
ut passed.
valgrind found no issue: