Skip to content

Application crashes when calling ctx->shutdown()

I've tried multiple hours debugging, but I can't figure out the proper way to shut down an application using C++ Lely Canopen API correctly.

I have an object that contains an AsyncMaster instance. In its destructor, I tried calling:

master->AsyncDeconfig().submit(exec, [&]() {
        // Perform a clean shutdown.
        ctx->shutdown();
      });

or

auto future = master->AsyncDeconfig();
while(!future.is_ready()){
   std::this_thread::yield();
}
ctx->shutdown();

or

exec.post(
        [this]()
        {
          ctx->shutdown();
        });

But I always get:

Thread 30 "LelyExecutable" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xffffad7ae1c0 (LWP 21118)]
0x0000fffff6c20610 in ___pthread_mutex_lock (mutex=mutex@entry=0xccccccc0c0000000) at ./nptl/pthread_mutex_lock.c:80

Backtrace (partial):

#0  0x0000fffff6c20610 in ___pthread_mutex_lock (mutex=mutex@entry=0xccccccc0c0000000) at ./nptl/pthread_mutex_lock.c:80
#1  0x0000fffff6c2652c in __mtx_lock (mutex=mutex@entry=0xccccccc0c0000000) at ../sysdeps/pthread/mtx_lock.c:25
#2  0x0000fffff40968cc in io_ctx_shutdown (ctx=0xccccccc0c0000000) at /home/ubuntu/ros2_iron/build/lely_core_libraries/upstream/src/io2/ctx.c:205
#3  0x0000ffffeee86bac in lely::io::ContextBase::shutdown (this=0xfffffffea6f8) at /home/ubuntu/ros2_iron/install/lely_core_libraries/include/lely/io2/ctx.hpp:90

it is definetly something going around with the io::Context object.

My application has 16 LoopDrivers attached to my AsyncMaster.

I find the API documentation unsupportive, and there's only one tutorial on the official website, thus I'm finding difficult to find hints on the web for this issue.