Skip to content

Fix segmentation fault during the destruction of ConsumerImpl #121

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

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Nov 22, 2022

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.

### 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.
@BewareMyPower
Copy link
Contributor Author

@RobertIndie PTAL first since you are the release manager of 3.1.0. I will depend on C++ client 3.1.0 on Python client. It's hard to reproduce because there is still something wrong with the Python client in my local env and I'm not sure why the current branch cannot expose this bug.

@BewareMyPower BewareMyPower merged commit 9f9314a into apache:main Nov 22, 2022
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-consumer-dtor-segfault branch November 22, 2022 11:01
RobertIndie pushed a commit that referenced this pull request Nov 23, 2022
### 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants