You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xy...@apache.org on 2022/11/23 02:36:34 UTC

[pulsar-client-cpp] tag v3.1.0-candidate-1 created (now 3b5aff7)

This is an automated email from the ASF dual-hosted git repository.

xyz pushed a change to tag v3.1.0-candidate-1
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git


      at 3b5aff7  (commit)
This tag includes the following new commits:

     new 3b5aff7  Fix segmentation fault during the destruction of ConsumerImpl (#121)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[pulsar-client-cpp] 01/01: Fix segmentation fault during the destruction of ConsumerImpl (#121)

Posted by xy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to tag v3.1.0-candidate-1
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git

commit 3b5aff7f7630295de6749bacfff53c2ebc63449c
Author: Yunze Xu <xy...@163.com>
AuthorDate: Tue Nov 22 19:01:07 2022 +0800

    Fix segmentation fault during the destruction of ConsumerImpl (#121)
    
    ### Motivation
    
    When I ran the tests of Python wrapper in my local env, I observed a
    segmentation fault. See the key stacktrace:
    
    ```
    #3  0x00007ffff6d742c5 in std::unique_lock<std::mutex>::lock() () from /usr/local/lib/python3.8/dist-packages/_pulsar.cpython-38-x86_64-linux-gnu.so
    #4  0x00007ffff6d72523 in std::unique_lock<std::mutex>::unique_lock(std::mutex&) ()
       from /usr/local/lib/python3.8/dist-packages/_pulsar.cpython-38-x86_64-linux-gnu.so
    #5  0x00007ffff67de193 in pulsar::ClientImpl::newRequestId (this=0x0) at /home/xyz/github.com/apache/pulsar-client-cpp/lib/ClientImpl.cc:644
    #6  0x00007ffff685d2c2 in pulsar::ConsumerImpl::~ConsumerImpl (this=0x7fff9800f9e0, __in_chrg=<optimized out>)
        at /home/xyz/github.com/apache/pulsar-client-cpp/lib/ConsumerImpl.cc:116
    ```
    
    In the destructor of `ConsumerImpl`, `client->newRequestId` might be
    called. However, `client` might be a null pointer because it's returned
    by `std::weak_ptr::lock()`.
    
    ### Modifications
    
    Add null check to avoid the segfault.
    
    (cherry picked from commit 9f9314a1fa4615d7fb9a01ab582ebfdd9259ca97)
---
 lib/ConsumerImpl.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/ConsumerImpl.cc b/lib/ConsumerImpl.cc
index c04a59e..41b13ae 100644
--- a/lib/ConsumerImpl.cc
+++ b/lib/ConsumerImpl.cc
@@ -127,11 +127,13 @@ ConsumerImpl::~ConsumerImpl() {
 
         ClientConnectionPtr cnx = getCnx().lock();
         ClientImplPtr client = client_.lock();
-        int requestId = client->newRequestId();
-        if (cnx) {
+        if (client && cnx) {
+            int requestId = client->newRequestId();
             cnx->sendRequestWithId(Commands::newCloseConsumer(consumerId_, requestId), requestId);
             cnx->removeConsumer(consumerId_);
             LOG_INFO(getName() << "Closed consumer for race condition: " << consumerId_);
+        } else {
+            LOG_WARN(getName() << "Client is destroyed and cannot send the CloseConsumer command");
         }
     }
     shutdown();