Skip to content

Conversation

@shibd
Copy link
Member

@shibd shibd commented Oct 16, 2025

Fix failed Node.js client test cpp 3.8.0 CI: https://github.com/apache/pulsar-client-node/actions/runs/18549226483/job/52888496279?pr=437

Motivation

Fix a segmentation fault when the consumer is closed.

* thread #6, stop reason = EXC_BAD_ACCESS (code=1, address=0x13c)
  * frame #0: 0x0000000102cae94c pulsar-tests`pulsar::SharedBuffer::readableBytes(this=0x0000000000000120) const at SharedBuffer.h:146:52
    frame #1: 0x0000000103212ce0 pulsar-tests`pulsar::Message::getLength(this=0x000000016d5f2670) const at Message.cc:57:64
    frame #2: 0x0000000103238410 pulsar-tests`pulsar::MultiTopicsConsumerImpl::messageProcessed(this=0x000000013800ba18, msg=0x000000016d5f2670) at MultiTopicsConsumerImpl.cc:1110:41
    frame #3: 0x0000000103238198 pulsar-tests`pulsar::MultiTopicsConsumerImpl::internalListener(this=0x000000013800ba18, consumer=0x00006000000c8668) at MultiTopicsConsumerImpl.cc:561:9
    frame #4: 0x0000000103256b2c pulsar-tests`decltype(*std::declval<std::__1::shared_ptr<pulsar::MultiTopicsConsumerImpl>&>().*std::declval<void (pulsar::MultiTopicsConsumerImpl::*&)(pulsar::Consumer const&)>()(std::declval<pulsar::Consumer&>())) std::__1::__invoke[abi:ne190102]<void (pulsar::MultiTopicsConsumerImpl::*&)(pulsar::Consumer const&), std::__1::shared_ptr<pulsar::MultiTopicsConsumerImpl>&, pulsar::Consumer&, void>(__f=0x00006000000c8648, __a0=std::__1::shared_ptr<pulsar::MultiTopicsConsumerImpl>::element_type @ 0x000000013800ba18 strong=9 weak=16, __args=0x00006000000c8668) at invoke.h:117:25

Root cause:

  1. When the consumer is closed, incomingMessages_ queue is closed.
  2. However, if there are in-flight messages before closing, they will be processed in the internalListener method, which attempts to pop message content from the incomingMessages_ queue.
  3. The closed incomingMessages_ will return null, leading to a segmentation fault when accessing the message.

Modifications

  1. Check if the message popping from incomingMessages_ false (indicating no more messages or queue closed). If so, return early.

Verifying this change

  • The testConsumerListenerShouldNotSegfaultAfterClose test can be used to reproduce and verify the fix for this issue.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@shibd shibd self-assigned this Oct 16, 2025
@shibd shibd added this to the 3.8.0 milestone Oct 16, 2025
@shibd shibd requested a review from BewareMyPower October 16, 2025 12:11
@BewareMyPower
Copy link
Contributor

Pulsar/ReaderTest.testHasMessageAvailableWhenCreated/0 also failed for master branch, not sure why it happened, I will take a look at this issue.

@BewareMyPower BewareMyPower added the bug Something isn't working label Oct 16, 2025
Co-authored-by: Yunze Xu <xyzinfernity@163.com>
@BewareMyPower BewareMyPower merged commit 386dedc into apache:main Oct 16, 2025
14 checks passed
BewareMyPower pushed a commit that referenced this pull request Oct 16, 2025
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.

2 participants