Skip to content

[Bug] testNegativeAckPrecisionBitCnt could cause segmentation fault #513

Closed

Description

@BewareMyPower

Search before asking

  • I searched in the issues and found nothing similar.

Version

master

Minimal reproduce step

Run this test

What did you expect to see?

success

What did you see instead?

crash

* thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000100339c98 pulsar-tests`pulsar::RetryableLookupService::getPartitionMetadataAsync(this=0x0000600002b08208)::'lambda'()::operator()() const at RetryableLookupService.h:63:56
   60  	    Future<Result, LookupDataResultPtr> getPartitionMetadataAsync(const TopicNamePtr& topicName) override {
   61  	        return partitionLookupCache_->run(
   62  	            "get-partition-metadata-" + topicName->toString(),
-> 63  	            [this, topicName] { return lookupService_->getPartitionMetadataAsync(topicName); });
   64  	    }
   65
   66  	    Future<Result, NamespaceTopicsPtr> getTopicsOfNamespaceAsync(
Target 0: (pulsar-tests) stopped.
(lldb) bt
* thread #3, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000100339c98 pulsar-tests`pulsar::RetryableLookupService::getPartitionMetadataAsync(this=0x0000600002b08208)::'lambda'()::operator()() const at RetryableLookupService.h:63:56
    frame #1: 0x0000000100339c58 pulsar-tests`decltype(std::declval<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'()&>()()) std::__1::__invoke[abi:ne180100]<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'()&>(__f=0x0000600002b08208) at invoke.h:344:25
    frame #2: 0x0000000100339c08 pulsar-tests`pulsar::Future<pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult>> std::__1::__invoke_void_return_wrapper<pulsar::Future<pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult>>, false>::__call[abi:ne180100]<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'()&>(__args=0x0000600002b08208) at invoke.h:411:12
    frame #3: 0x0000000100339bdc pulsar-tests`std::__1::__function::__alloc_func<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'(), std::__1::allocator<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'()>, pulsar::Future<pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult>> ()>::operator()[abi:ne180100](this=0x0000600002b08208) at function.h:169:12
    frame #4: 0x0000000100338978 pulsar-tests`std::__1::__function::__func<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'(), std::__1::allocator<pulsar::RetryableLookupService::getPartitionMetadataAsync(std::__1::shared_ptr<pulsar::TopicName> const&)::'lambda'()>, pulsar::Future<pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult>> ()>::operator()(this=0x0000600002b08200) at function.h:311:10
    frame #5: 0x000000010032fd60 pulsar-tests`std::__1::__function::__value_func<pulsar::Future<pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult>> ()>::operator()[abi:ne180100](this=0x000000013b809440) const at function.h:428:12
    frame #6: 0x000000010032fb9c pulsar-tests`std::__1::function<pulsar::Future<pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult>> ()>::operator()(this= Lambda in File RetryableLookupService.h at Line 63) const at function.h:981:10
    frame #7: 0x000000010032fa24 pulsar-tests`pulsar::RetryableOperation<std::__1::shared_ptr<pulsar::LookupDataResult>>::runImpl(this=0x000000013b809418, remainingTime=(__rep_ = 29900000000)) at RetryableOperation.h:90:9
    frame #8: 0x000000010033306c pulsar-tests`pulsar::RetryableOperation<std::__1::shared_ptr<pulsar::LookupDataResult>>::runImpl(this=0x000000016ff12810, ec=0x000000016ff12830)::'lambda'(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&)::operator()(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&) const::'lambda'(std::__1::error_code const&)::operator()(std::__1::error_code const&) const at RetryableOperation.h:129:21
    frame #9: 0x0000000100332ba4 pulsar-tests`asio::detail::binder1<pulsar::RetryableOperation<std::__1::shared_ptr<pulsar::LookupDataResult>>::runImpl(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>)::'lambda'(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&)::operator()(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&) const::'lambda'(std::__1::error_code const&), std::__1::error_code>::operator()(this=0x000000016ff12810) at bind_handler.hpp:114:5
    frame #10: 0x00000001003329e4 pulsar-tests`void asio::detail::handler_work<pulsar::RetryableOperation<std::__1::shared_ptr<pulsar::LookupDataResult>>::runImpl(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>)::'lambda'(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&)::operator()(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&) const::'lambda'(std::__1::error_code const&), asio::any_io_executor, void>::complete<asio::detail::binder1<pulsar::RetryableOperation<std::__1::shared_ptr<pulsar::LookupDataResult>>::runImpl(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>)::'lambda'(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&)::operator()(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&) const::'lambda'(std::__1::error_code const&), std::__1::error_code>>(this=0x000000016ff12880, function=0x000000016ff12810, handler=0x000000016ff12810) at handler_work.hpp:469:7
    frame #11: 0x000000010033276c pulsar-tests`asio::detail::wait_handler<pulsar::RetryableOperation<std::__1::shared_ptr<pulsar::LookupDataResult>>::runImpl(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>)::'lambda'(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&)::operator()(pulsar::Result, std::__1::shared_ptr<pulsar::LookupDataResult> const&) const::'lambda'(std::__1::error_code const&), asio::any_io_executor>::do_complete(owner=0x000000013b6044d0, base=0x000000014b726c50, (null)=0x000000016ff12ae8, (null)=0) at wait_handler.hpp:75:9
    frame #12: 0x0000000100063440 pulsar-tests`asio::detail::scheduler_operation::complete(this=0x000000014b726c50, owner=0x000000013b6044d0, ec=0x000000016ff12ae8, bytes_transferred=0) at scheduler_operation.hpp:39:5
    frame #13: 0x0000000100062d60 pulsar-tests`asio::detail::scheduler::do_run_one(this=0x000000013b6044d0, lock=0x000000016ff129c8, this_thread=0x000000016ff12a00, ec=0x000000016ff12ae8) at scheduler.ipp:492:12
    frame #14: 0x00000001000629c8 pulsar-tests`asio::detail::scheduler::run(this=0x000000013b6044d0, ec=0x000000016ff12ae8) at scheduler.ipp:209:10
    frame #15: 0x000000010074d640 pulsar-tests`asio::io_context::run(this=0x0000600001e30028) at io_context.ipp:63:24
    frame #16: 0x000000010074d124 pulsar-tests`pulsar::ExecutorService::start()::$_0::operator()(this=0x0000600002b30328) const at ExecutorService.cc:39:29
    frame #17: 0x000000010074cfc8 pulsar-tests`decltype(std::declval<pulsar::ExecutorService::start()::$_0>()()) std::__1::__invoke[abi:ne180100]<pulsar::ExecutorService::start()::$_0>(__f=0x0000600002b30328) at invoke.h:344:25
    frame #18: 0x000000010074cfa4 pulsar-tests`void std::__1::__thread_execute[abi:ne180100]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, pulsar::ExecutorService::start()::$_0>(__t=size=2, (null)=__tuple_indices<> @ 0x000000016ff12f7f) at thread.h:199:3
    frame #19: 0x000000010074cbb4 pulsar-tests`void* std::__1::__thread_proxy[abi:ne180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, pulsar::ExecutorService::start()::$_0>>(__vp=0x0000600002b30320) at thread.h:208:3
    frame #20: 0x00000001841d32e4 libsystem_pthread.dylib`_pthread_start + 136
(lldb) p lookupService_
(const std::shared_ptr<pulsar::LookupService>) nullptr {
  __ptr_ = nullptr
}

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added this to the 3.8.0 milestone on Oct 16, 2025
  2. removed this from the 3.8.0 milestone on Oct 17, 2025
  3. BewareMyPower commented on Oct 21, 2025

    @BewareMyPower
    ContributorAuthor

    When running node client tests inside a ubuntu 22.04 container, it crashed with the same error.

    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  0x0000ffff7f5917e8 in std::_Function_handler<pulsar::Future<pulsar::Result, std::shared_ptr<pulsar::LookupDataResult> > (), pulsar::RetryableLookupService::getPartitionMetadataAsync(std::shared_ptr<pulsar::TopicName> const&)::{lambda()#1}>::_M_invoke(std::_Any_data const&) () from /root/pulsar-client-node/lib/binding/pulsar.node
    [Current thread is 1 (Thread 0xffff7e80f040 (LWP 8462))]
    (gdb) bt
    #0  0x0000ffff7f5917e8 in std::_Function_handler<pulsar::Future<pulsar::Result, std::shared_ptr<pulsar::LookupDataResult> > (), pulsar::RetryableLookupService::getPartitionMetadataAsync(std::shared_ptr<pulsar::TopicName> const&)::{lambda()#1}>::_M_invoke(std::_Any_data const&) () from /root/pulsar-client-node/lib/binding/pulsar.node
    #1  0x0000ffff7f59c2b8 in pulsar::RetryableOperation<std::shared_ptr<pulsar::LookupDataResult> >::runImpl(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) () from /root/pulsar-client-node/lib/binding/pulsar.node
    #2  0x0000ffff7f59d7e4 in pulsar::RetryableOperation<std::shared_ptr<pulsar::LookupDataResult> >::runImpl(std::chrono::duration<long, std::ratio<1l, 1000000000l> >)::{lambda(pulsar::Result, std::shared_ptr<pulsar::LookupDataResult> const&)#1}::operator()(pulsar::Result, std::shared_ptr<pulsar::LookupDataResult> const&) const::{lambda(std::error_code const&)#1}::operator()(std::error_code const&) const () from /root/pulsar-client-node/lib/binding/pulsar.node
    #3  0x0000ffff7f5a6b04 in asio::detail::wait_handler<pulsar::RetryableOperation<std::shared_ptr<pulsar::LookupDataResult> >::runImpl(std::chrono::duration<long, std::ratio<1l, 1000000000l> >)::{lambda(pulsar::Result, std::shared_ptr<pulsar::LookupDataResult> const&)#1}::operator()(pulsar::Result, std::shared_ptr<pulsar::LookupDataResult> const&) const::{lambda(std::error_code const&)#1}, asio::any_io_executor>::do_complete(void*, asio::detail::scheduler_operation*, std::error_code const&, unsigned long) () from /root/pulsar-client-node/lib/binding/pulsar.node
    

    But the error is not similar to apache/pulsar-client-node#437 (comment)

    /cc @shibd

  4. BewareMyPower commented on Oct 21, 2025

    @BewareMyPower
    ContributorAuthor

    After removing the allowAutoTopicCreationType=partitioned config, the issue becomes #516

  5. BewareMyPower commented on Nov 5, 2025

    @BewareMyPower
    ContributorAuthor
        frame #3: 0x0000000100702328 pulsar-tests`void std::__1::condition_variable::wait<QueueNotEmpty<UnboundedBlockingQueue<pulsar::Message>>>(this=0x000000012100e628, __lk=0x000000016fdfded8, __pred=QueueNotEmpty<UnboundedBlockingQueue<pulsar::Message> > @ 0x000000016fdfde98) at condition_variable.h:146:5
        frame #4: 0x00000001006c1888 pulsar-tests`UnboundedBlockingQueue<pulsar::Message>::pop(this=0x000000012100e5e8, value=0x000000016fdfe1b0) at UnboundedBlockingQueue.h:61:30
        frame #5: 0x0000000100790af8 pulsar-tests`pulsar::MultiTopicsConsumerImpl::receive(this=0x000000012100d818, msg=0x000000016fdfe1b0) at MultiTopicsConsumerImpl.cc:580:23
        frame #6: 0x00000001006a0360 pulsar-tests`pulsar::Consumer::receive(this=0x000000016fdfe2c8, msg=0x000000016fdfe1b0) at Consumer.cc:71:19
        frame #7: 0x00000001000dda7c pulsar-tests`testNegativeAckPrecisionBitCnt(topic="testNegativeAckPrecisionBitCnt-12-1762309881", precisionBitCnt=12) at BasicEndToEndTest.cc:3284:14
    
  6. BewareMyPower commented on Nov 5, 2025

    @BewareMyPower
    ContributorAuthor

    I added some logs and found the root cause.

    @@ -38,13 +39,18 @@ class RetryableLookupService : public LookupService {
        public:
         template <typename... Args>
         explicit RetryableLookupService(PassKey, Args&&... args)
    -        : RetryableLookupService(std::forward<Args>(args)...) {}
    +        : RetryableLookupService(std::forward<Args>(args)...) {
    +        LOG_INFO("XYZ created RetryableLookupService " << (void*)this);
    +    }
    +
    +    ~RetryableLookupService() override { LOG_INFO("XYZ destroyed RetryableLookupService " << (void*)this); }
    
         void close() override {
             lookupCache_->clear();
             partitionLookupCache_->clear();
             namespaceLookupCache_->clear();
             getSchemaCache_->clear();
    +        LOG_INFO("XYZ closed RetryableLookupService " << (void*)this);
         }
    
         template <typename... Args>
    @@ -58,9 +64,14 @@ class RetryableLookupService : public LookupService {
         }
    
         Future<Result, LookupDataResultPtr> getPartitionMetadataAsync(const TopicNamePtr& topicName) override {
    +        LOG_INFO("XYZ " << (void*)this << " before getPartitionMetadataAsync for topic "
    +                        << topicName->toString());
             return partitionLookupCache_->run(
    -            "get-partition-metadata-" + topicName->toString(),
    -            [this, topicName] { return lookupService_->getPartitionMetadataAsync(topicName); });
    +            "get-partition-metadata-" + topicName->toString(), [this, topicName] {
    +                LOG_INFO("XYZ " << (void*)this << " after getPartitionMetadataAsync for topic "
    +                                << topicName->toString());
    +                return lookupService_->getPartitionMetadataAsync(topicName);
    +            });
         }
    2025-11-05 13:16:33.171 INFO  [0x1ee9d7840] RetryableLookupService:43 | XYZ created RetryableLookupService 0x600001b95128
    2025-11-05 13:16:33.171 INFO  [0x1ee9d7840] RetryableLookupService:68 | XYZ 0x600001b95128 before getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    2025-11-05 13:16:33.171 INFO  [0x1ee9d7840] RetryableLookupService:72 | XYZ 0x600001b95128 after getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    2025-11-05 13:16:33.230 INFO  [0x1ee9d7840] RetryableLookupService:68 | XYZ 0x600001b95128 before getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    2025-11-05 13:16:33.230 INFO  [0x1ee9d7840] RetryableLookupService:72 | XYZ 0x600001b95128 after getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    2025-11-05 13:16:35.250 INFO  [0x17002b000] RetryableLookupService:68 | XYZ 0x600001b95128 before getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    2025-11-05 13:16:35.255 INFO  [0x17002b000] RetryableLookupService:72 | XYZ 0x600001b95128 after getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    2025-11-05 13:16:35.259 INFO  [0x1ee9d7840] RetryableLookupService:46 | XYZ destroyed RetryableLookupService 0x600001b95128
    2025-11-05 13:16:35.356 INFO  [0x16ff13000] RetryableLookupService:72 | XYZ 0x600001b95128 after getPartitionMetadataAsync for topic persistent://public/default/testNegativeAckPrecisionBitCnt-11-1762319793
    

    The function passed to RetryableOperation captures a pointer to the RetryableLookupService. After the RetryableLookupService object is destroyed, the function could still be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions