intrepidcs / icsscand

User-mode SocketCAN daemon for Intrepid devices
BSD 2-Clause "Simplified" License
10 stars 6 forks source link

Daemon crashes on disconnecting ValueCan #8

Open magcsaba opened 2 years ago

magcsaba commented 2 years ago

Daemon crashes with Segmentation Fault on disconnecting ValueCan on Linux.

It seems that on DeviceDisconnected event wants to log the device properties but the device object is already destroyed.

This is the GDB stack trace:

#0  0x00007ffff0005600 in ?? ()
#1  0x0000555555727e91 in icsneo::Device::describe[abi:cxx11]() const (this=0x7ffff00162e0)
    at /home/csabam/work/source/icsscand/third-party/libicsneo/device/device.cpp:87
#2  0x00005555556cc9bc in icsneo::operator<< (os=..., device=...)
    at /home/csabam/work/source/icsscand/third-party/libicsneo/include/icsneo/device/device.h:56
#3  0x00005555556cbff4 in icsneo::APIEvent::describe[abi:cxx11]() const (this=0x7fffec000f50)
    at /home/csabam/work/source/icsscand/third-party/libicsneo/api/icsneocpp/event.cpp:28
#4  0x00005555556bb287 in searchForDevices () at /home/csabam/work/source/icsscand/src/main.cpp:347
#5  0x00005555556bb6c2 in deviceSearchThread () at /home/csabam/work/source/icsscand/src/main.cpp:355
#6  0x00005555556cad4d in std::__invoke_impl<void, void (*)()> (
    __f=@0x555555833768: 0x5555556bb68f <deviceSearchThread()>) at /usr/include/c++/9/bits/invoke.h:60
#7  0x00005555556cacf9 in std::__invoke<void (*)()> (
    __fn=@0x555555833768: 0x5555556bb68f <deviceSearchThread()>) at /usr/include/c++/9/bits/invoke.h:95
#8  0x00005555556cac9a in std::thread::_Invoker<std::tuple<void (*)()> >::_M_invoke<0ul> (
    this=0x555555833768) at /usr/include/c++/9/thread:244
#9  0x00005555556cabbe in std::thread::_Invoker<std::tuple<void (*)()> >::operator() (
    this=0x555555833768) at /usr/include/c++/9/thread:251
#10 0x00005555556caa36 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)()> > >::_M_run (this=0x555555833760) at /usr/include/c++/9/thread:195
#11 0x00007ffff7e1cde4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#12 0x00007ffff7f7b609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#13 0x00007ffff7c58163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
hollinsky-intrepid commented 2 years ago

Yes, looks like the APIEvent should be holding an std::weak_ptr<Device> rather than a Device*. We'll take a closer look at this, I suspect we want to address it in libicsneo directly or we will see more of this same class of bug.

Is your use case able to work around the issue for a short while we fix this more permanently?

magcsaba commented 2 years ago

I have already modified the code locally to not log device details for any Event. I know this is not a solution, but for me temporary it is good enough to be able to use the software.

Thank you for looking into it!