dawonn / vectornav

ROS Interface for the VectorNav IMU/GPS
147 stars 179 forks source link

Fix reconnect and segfault issues #113

Closed richardw347 closed 1 year ago

richardw347 commented 1 year ago

This PR fixes two issue we've experienced using the driver with the VN-100 on a mobile robot running ROS 2 Humble.

[  829.578417] vectornav[7502]: segfault at 7f57ad058fba ip 00007f5081bcfa2b sp 00007f506fffe150 error 4 in libvncxx.so[7f5081ba0000+51000]
[  829.578427] Code: ff 48 89 85 58 fe ff ff e9 f2 04 00 00 48 8d 85 58 fe ff ff 48 89 c7 e8 43 97 fd ff 48 89 85 b8 fe ff ff 48 8b 85 b8 fe ff ff <0f> b6 40 08 83 f0 01 84 c0 74 59 48 8b 85 b8 fe ff ff c6 40 08 01

I tracked this down to an issue with how the driver was cleaning up when it reconnects. Every time connect is called on the vn::sensors::VnSensor object it spawns a new thread to handle the serial port. If disconnect is never called then the thread is never exited and will keep going. For us when the driver was trying to reconnect it ended with multiple threads running which was causing segfaults because of invalid iterators in the dataReceieved callback of packet_finder.cpp.

What I've tried to so with the changes I made was make sure to disconnect and clean up the VnSensor object whenever the driver reconnects and this has fixed the issue for us. We have been able to run the driver reliably without and segfaults and happily disconnect/reconnecting without any issues.