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)
Examples for using the API to publish and consume messages can be found under the examples folder.
Pulsar C++ client uses doxygen to build API documents. After installing doxygen, you only need to run doxygen to generate the API documents whose main page is under the doxygen/html/index.html path.
The default supported compression types are:
CompressionNoneCompressionLZ4If you want to enable other compression types, you need to install:
If you want to build and run the tests, you need to install GTest. Otherwise, you need to add CMake option -DBUILD_TESTS=OFF.
If you want to use ClientConfiguration::setLogConfFilePath, you need to install the Log4CXX and add CMake option -DUSE_LOG4CXX=ON.
Pulsar C++ Client Library has been tested on:
First of all, clone the source code:
git clone https://github.com/apache/pulsar-client-cpp cd pulsar-client-cpp
sudo apt-get update -y && apt-get install -y g++ cmake libssl-dev libcurl4-openssl-dev \ libprotobuf-dev libboost-all-dev libgtest-dev libgmock-dev \ protobuf-compiler
cmake . make
Client library will be placed in:
lib/libpulsar.so lib/libpulsar.a
Tools will be placed in:
perf/perfProducer perf/perfConsumer
brew install openssl protobuf boost boost-python3 googletest zstd snappy
cmake . make
Client library will be placed in:
lib/libpulsar.dylib lib/libpulsar.a
Tools will be placed in:
perf/perfProducer perf/perfConsumer
It‘s highly recommended to use vcpkg for C++ package management on Windows. It’s easy to install and well supported by Visual Studio (2015/2017/2019) and CMake. See here for quick start.
Take Windows 64-bit library as an example, you only need to run
vcpkg install --feature-flags=manifests --triplet x64-windows
NOTE: For Windows 32-bit library, change
x64-windowstox86-windows, see here for more details about the triplet concept in Vcpkg.
The all dependencies, which are specified by vcpkg.json, will be installed in vcpkg_installed/ subdirectory,
With vcpkg, you only need to run two commands:
cmake \ -B ./build \ -A x64 \ -DBUILD_TESTS=OFF \ -DVCPKG_TRIPLET=x64-windows \ -DCMAKE_BUILD_TYPE=Release \ -S . cmake --build ./build --config Release
Then all artifacts will be built into build subdirectory.
NOTE:
- For Windows 32-bit, you need to use
-A Win32and-DVCPKG_TRIPLET=x86-windows.- For MSVC Debug mode, you need to replace
ReleasewithDebugfor bothCMAKE_BUILD_TYPEvariable and--configoption.
You need to install dlfcn-win32 in addition.
If you installed the dependencies manually, you need to run
#If all dependencies are in your path, all that is necessary is cmake . #if all dependencies are not in your path, then passing in a PROTOC_PATH and CMAKE_PREFIX_PATH is necessary cmake -DPROTOC_PATH=C:/protobuf/bin/protoc -DCMAKE_PREFIX_PATH="C:/boost;C:/openssl;C:/zlib;C:/curl;C:/protobuf;C:/googletest;C:/dlfcn-win32" . #This will generate pulsar-cpp.sln. Open this in Visual Studio and build the desired configurations.
Client library will be placed in:
build/lib/Release/pulsar.lib build/lib/Release/pulsar.dll
Add windows environment paths:
build/lib/Release vcpkg_installed
Examples will be available in:
build/examples/Release
# Execution # Start standalone broker ./pulsar-test-service-start.sh # Run the tests cd tests ./pulsar-tests # When no longer needed, stop standalone broker ./pulsar-test-service-stop.sh
It's required to install LLVM for clang-tidy and clang-format. Pulsar C++ client use clang-format 11 to format files. make format automatically formats the files.
For Ubuntu users, you can install clang-format-11 via apt install clang-format-11. For other users, run ./build-support/docker-format.sh if you have Docker installed.
We welcome contributions from the open source community, kindly make sure your changes are backward compatible with GCC 4.8 and Boost 1.53.