shibd opened a new pull request, #510:
URL: https://github.com/apache/pulsar-client-cpp/pull/510

   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
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
   
   - [x] `doc-not-needed` 
   (Please explain why)
   
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to