apache / apache/pulsar-client-cpp
[Bug] `std::bad_function_call` was thrown on `Reader::ReadNext` on a non-persistent topic
- 主要语言
- C++
- 星标
- 71
- 派生
- 90
- 平均合并
- 2 小时 33 分钟
- 30 天内合并 PR
- 3
描述
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/pulsar-client-cpp/issues) and found nothing similar.
### Version
Pulsar 3.3.2 running in docker, same issue also happen when I tried to connect to StreamNative cloud serivce. But I think this issue has notthing to do with the pulser server side. And I am using pulsar-client-cpp 3.5.1.
### Minimal reproduce step
1. Create a `Reader` on a non-persistent topic.
2. Call `ReadNext` on the Reader instance to read messages.
### What did you expect to see?
Messages are successfully read by the client.
### What did you see instead?
A portion of the exception backtrace:
```
0. std::exception::capture() @ 0x00000000245a0b24
1. std::exception::exception[abi:v15000]() @ 0x00000000245a0aec
2. std::__1::bad_function_call::bad_function_call() @ 0x00000000245a0a9c
3. std::__1::__throw_bad_function_call[abi:v15000]() @ 0x00000000245a0a50
4. ? @ 0x000000003e7c3b18
5. ./build_docker/../contrib/llvm-project/libcxx/include/__functional/function.h:848: std::__1::__function::__policy_func::operator()[abi:v15000](pulsar::Result&&) const @ 0x000000003e83edc8
6. ./build_docker/../contrib/llvm-project/libcxx/include/__functional/function.h:1187: std::__1::function::operator()(pulsar::Result) const @ 0x000000003e7db9e4
7. ./build_docker/../contrib/pulsar-cmake/pulsar-client-cpp/lib/AckGroupingTracker.h:93: pulsar::AckGroupingTracker::addAcknowledgeCumulative(pulsar::MessageId const&, std::__1::function) @ 0x000000003e95a38c
8. ./build_docker/../contrib/pulsar-cmake/pulsar-client-cpp/lib/ConsumerImpl.cc:1187: pulsar::ConsumerImpl::acknowledgeCumulativeAsync(pulsar::MessageId const&, std::__1::function) @ 0x000000003e93ce34
9. ./build_docker/../contrib/pulsar-cmake/pulsar-client-cpp/lib/ReaderImpl.cc:155: pulsar::ReaderImpl::acknowledgeIfNecessary(pulsar::Result, pulsar::Message const&) @ 0x000000003ea6a8b0
10. ./build_docker/../contrib/pulsar-cmake/pulsar-client-cpp/lib/ReaderImpl.cc:130: pulsar::ReaderImpl::readNext(pulsar::Message&, int) @ 0x000000003ea6a954
11. ./build_docker/../contrib/pulsar-cmake/pulsar-client-cpp/lib/Reader.cc:49: pulsar::Reader::readNext(pulsar::Message&, int) @ 0x000000003ea66ccc
```
### Anything else?
I think the issue is that, `AckGroupingTracker::addAcknowledgeList` does check `callback` before calling it: https://github.com/apache/pulsar-client-cpp/blob/main/lib/AckGroupingTracker.h#L81-L83. And in `ReaderImpl::acknowledgeIfNecessary` it passes the `emptyCallback` caused the issue: https://github.com/apache/pulsar-client-cpp/blob/main/lib/ReaderImpl.cc#L155
### Are you willing to submit a PR?
- [X] I'm willing to submit a PR!
贡献指南
调研方向
先阅读 lib/ReaderImpl.cc 中的 acknowledgeIfNecessary 和 lib/AckGroupingTracker.h 中的 addAcknowledgeList,然后在非持久化 topic 上复现一个 Reader 并调用 ReadNext。完成的标准是客户端不再抛出 std::bad_function_call,并且消息能够成功读取。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp
- 领域
- distributed-systems
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100