BewareMyPower commented on issue #9796:
URL: https://github.com/apache/pulsar/issues/9796#issuecomment-803049518
**Good news, I just found the problem.**
Wait, I just found your callback
```c++
pulsar::SendCallback callback(Result res, const pulsar::MessageId &msgId)
{
if (pulsar::ResultOk == res)
{
cout << "Receive the callback: " << res << ", with message id:" <<
msgId << endl;
}
else
{
cout << "Receive the failed callback" << res << ", with message id:"
<< msgId << endl;
}
}
```
You used `pulsar::SendCallback` as the returned value? And the function has
no `return`?
`sendAsync` accepts a `SendCallback` as the param:
```c++
typedef std::function<void(Result, const MessageId& messageId)> SendCallback;
```
It returns `void`. You just passed `std::function<std::function<Result,
const MessageId&> (Result, const MessageId&)>` to `sendAsync`. I think it's a
UB in C++ and I've no interest in exploring how this UB causes a segmentation
fault.
At last, I've two suggestions:
1. If you're using GCC but not Clang, please add the `-Wall` option. Then
you can see the warning like:
```bash
# g++ main.cc -std=c++11 -I include/ -L lib/ -lpulsar -Wall
main.cc: In function 'pulsar::SendCallback callback(pulsar::Result, const
pulsar::MessageId&)':
main.cc:9:1: warning: no return statement in function returning non-void
[-Wreturn-type]
}
```
2. When you're opening an issue and someone gave your some advice, please
make sure you've followed the suggestion to avoid wasting time.
> As I tried above you support, there is the same error as before,
I think the callbacks I provided all return `void` instead of
`pulsar::SendCallback`, if you did follow my suggestion, the simplest way that
is just pasting my code and run, the segmentation fault won't happen.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]