BewareMyPower commented on issue #14848:
URL: https://github.com/apache/pulsar/issues/14848#issuecomment-1240369806

   Eventually I have another way to reproduce this bug.
   
   ```diff
   diff --git a/pulsar-client-cpp/lib/ConsumerImpl.cc 
b/pulsar-client-cpp/lib/ConsumerImpl.cc
   index 79c20d8464..b881e508fd 100644
   --- a/pulsar-client-cpp/lib/ConsumerImpl.cc
   +++ b/pulsar-client-cpp/lib/ConsumerImpl.cc
   @@ -141,6 +141,7 @@ const std::string& ConsumerImpl::getSubscriptionName() 
const { return originalSu
    const std::string& ConsumerImpl::getTopic() const { return topic_; }
    
    void ConsumerImpl::start() {
   +    consumerCreatedPromise_.setValue(shared_from_this());
        HandlerBase::start();
    
        // Initialize ackGroupingTrackerPtr_ here because the 
shared_from_this() was not initialized until the
   ```
   
   With this patch, which simulates the case that the `start()` completes very 
quickly, the test failure can be reproduced easily.
   
   ```
   $ ./tests/main --gtest_filter='ClientTest.testReferenceCount'                
  
   Note: Google Test filter = ClientTest.testReferenceCount
   [==========] Running 1 test from 1 test suite.
   [----------] Global test environment set-up.
   [----------] 1 test from ClientTest
   [ RUN      ] ClientTest.testReferenceCount
   2022-09-08 16:02:59.928 INFO  [0x117ff5600] ClientConnection:189 | [<none> 
-> pulsar://localhost:6650] Create ClientConnection, timeout=10000
   2022-09-08 16:02:59.928 INFO  [0x117ff5600] ConnectionPool:96 | Created 
connection for pulsar://localhost:6650
   2022-09-08 16:02:59.930 INFO  [0x7000039be000] ClientConnection:375 | 
[127.0.0.1:60899 -> 127.0.0.1:6650] Connected to broker
   2022-09-08 16:02:59.931 INFO  [0x7000039be000] HandlerBase:61 | 
[persistent://public/default/client-test-reference-count-1662624179, ] Getting 
connection from pool
   2022-09-08 16:03:00.033 INFO  [0x7000039be000] ProducerImpl:174 | 
[persistent://public/default/client-test-reference-count-1662624179, ] Created 
producer on broker [127.0.0.1:60899 -> 127.0.0.1:6650] 
   2022-09-08 16:03:00.033 INFO  [0x117ff5600] ClientTest:198 | Reference count 
of the producer: 1
   2022-09-08 16:03:00.034 INFO  [0x117ff5600] Client:88 | Subscribing on Topic 
:client-test-reference-count-1662624179
   2022-09-08 16:03:00.034 INFO  [0x7000039be000] HandlerBase:61 | 
[persistent://public/default/client-test-reference-count-1662624179, my-sub, 0] 
Getting connection from pool
   2022-09-08 16:03:00.035 INFO  [0x117ff5600] ClientTest:204 | Reference count 
of the consumer: 2
   2022-09-08 16:03:00.054 INFO  [0x7000039be000] HandlerBase:61 | 
[persistent://public/default/client-test-reference-count-1662624179-reader, 
reader-35d115ff2d, 1] Getting connection from pool
   2022-09-08 16:03:00.054 INFO  [0x117ff5600] ClientTest:212 | Reference count 
of the reader's underlying consumer: 1
   2022-09-08 16:03:00.054 INFO  [0x117ff5600] ClientTest:216 | Reference count 
of the reader: 3
   2022-09-08 16:03:00.054 INFO  [0x117ff5600] ProducerImpl:618 | Producer - 
[persistent://public/default/client-test-reference-count-1662624179, 
standalone-0-537] , [batchMessageContainer = { BatchMessageContainer [size = 0] 
[bytes = 0] [maxSize = 1000] [maxBytes = 131072] [topicName = 
persistent://public/default/client-test-reference-count-1662624179] 
[numberOfBatchesSent_ = 0] [averageBatchSize_ = 0] }]
   2022-09-08 16:03:00.054 WARN  [0x117ff5600] ProducerImpl:115 | 
[persistent://public/default/client-test-reference-count-1662624179, 
standalone-0-537] Destroyed producer which was not properly closed
   
/Users/xuyunze/github.com/BewareMyPower/pulsar/pulsar-client-cpp/tests/ClientTest.cc:222:
 Failure
   Expected equality of these values:
     consumers[0].use_count()
       Which is: 1
     0
   [  FAILED  ] ClientTest.testReferenceCount (127 ms)
   [----------] 1 test from ClientTest (127 ms total)
   
   [----------] Global test environment tear-down
   [==========] 2022-09-08 16:03:00.054 INFO  [0x7000039be000] ConsumerImpl:221 
| [persistent://public/default/client-test-reference-count-1662624179, my-sub, 
0] Created consumer on broker [127.0.0.1:60899 -> 127.0.0.1:6650] 
   1 test from 1 test suite ran. (127 ms total)
   [  PASSED  ] 0 tests.
   2022-09-08 16:03:00.054 WARN  [0x7000039be000] ConsumerImpl:116 | 
[persistent://public/default/client-test-reference-count-1662624179, my-sub, 0] 
Destroyed consumer which was not properly closed
   [  FAILED  ] 1 test, listed below:
   2022-09-08 16:03:00.054 INFO  [0x7000039be000] ConsumerImpl:124 | 
[persistent://public/default/client-test-reference-count-1662624179, my-sub, 0] 
Closed consumer for race condition: 0
   [  FAILED  ] ClientTest.testReferenceCount
   ```
   
   I'll push a new PR to fix it.


-- 
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