apache / apache/pulsar-client-cpp

[Bug] `std::bad_function_call` was thrown on `Reader::ReadNext` on a non-persistent topic

オープン
#455 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
71
フォーク
90
平均マージ
2時間 33分
マージ済み PR(30日)
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 を読み、次に非永続トピック上で Reader を再現して ReadNext を呼び出します。完了条件は、クライアントが std::bad_function_call をスローしなくなり、メッセージが正常に読み取れることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
distributed-systems
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。