BewareMyPower opened a new pull request, #17239: URL: https://github.com/apache/pulsar/pull/17239
### Motivation When a multi-topics consumer fails to create, it will close all internal single consumers. In this case, segmentation fault will happen. https://github.com/apache/pulsar/blob/8286e8ccb2e1433814c306607c6f218ca548752a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc#L369-L374 https://github.com/apache/pulsar/blob/8286e8ccb2e1433814c306607c6f218ca548752a/pulsar-client-cpp/lib/ConsumerImpl.cc#L984-L989 If the single consumer failed to create, the callback here (`handleSingleConsumerClose`) will be called immediately in the range for loop of `consumers_`. However, the callback also modified the `consumers_` by calling `remove` and `clear` methods. ### Modifications - Add a new overload for `SynchronizedHashMap::clear` that accepts a callback on the key-value. This `clear` overload calls the callback on each key-value pair before removing it. Use this `clear` overload instead of `forEach` in `MultiTopicsConsumerImpl::closeAsync`. - Add an atomic result field `failedResult` to save the 1st error code when creating a multi-topics consumer. Complete the `multiTopicsConsumerCreatedPromise_` with this cached result in the callback of `closeAsync`. ### Verifying this change - [ ] Make sure that the change passes the CI checks. - Modify `SynchronizedHashMap::testClear` to verify the new overload of `clear` method. - Modify `ClientTest::testWrongListener` to cover the case when a multi-topics consumer is closed by a failed creation. ### Documentation Check the box below or label this PR directly. Need to update docs? - [ ] `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]
