eclipse-paho / paho.mqtt.cpp

Other
1.03k stars 438 forks source link

Operation not permitted on try_consume_message async #474

Open candaj2 opened 9 months ago

candaj2 commented 9 months ago

Hello, I'm having an issue using the try_consume_message(const_message_ptr *msg) method. When executing it's always throwing a "std::system_error" exception. You can find following the stacktrace:

` terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted
--Type <RET> for more, q to quit, c to continue without paging--

Thread 5 "server" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffebfff700 (LWP 188904)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff6fec537 in __GI_abort () at abort.c:79
#2  0x00007ffff72757ec in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff7280966 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff72809d1 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff7280c65 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7278458 in std::__throw_system_error(int) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00005555561e38d8 in std::unique_lock<std::mutex>::lock (this=0x7fffebffe5c0) at /usr/include/c++/10/bits/unique_lock.h:133
#8  0x00005555561e2831 in std::unique_lock<std::mutex>::unique_lock (this=0x7fffebffe5c0, __m=...) at /usr/include/c++/10/bits/unique_lock.h:68
#9  0x00007ffff7f5a365 in mqtt::thread_queue<std::shared_ptr<mqtt::message const>, std::deque<std::shared_ptr<mqtt::message const>, std::allocator<std::shared_ptr<mqtt::message const> > > >::try_get(std::shared_ptr<mqtt::message const>*) () from /usr/local/lib/libpaho-mqttpp3.so.1
#10 0x00007ffff7f588a6 in mqtt::async_client::try_consume_message(std::shared_ptr<mqtt::message const>*) () 
`

Is there any known issue about that ? I'm in v1.3.2 and can share a code without the boilerplate if needed

candaj2 commented 8 months ago

Hello, Can someone have any idea about that

fpagliughi commented 3 months ago

Yes, please share a small code sample with the problem.

fpagliughi commented 3 months ago

I can't reproduce this in the latest development branches ('v1.4.x' and 'develop').

I modified the read loop in the async_consumer_v5 sample app as follows:

while (true) {
    mqtt::const_message_ptr msg;

    if (!cli.try_consume_message(&msg)) {
        this_thread::sleep_for(100ms);
        continue;
    }

    if (!msg)
        break;

    cout << msg->get_topic() << ": " << msg->to_string() << endl;
}

Works for me.