[Sponsored by CubePilot] Try to fix potential mavlink segfaults on USB disconnect
This is an attempt at fixing the segfaults we sometimes see when disconnecting USB and stopping the mavlink instance.
There are reports in various places:
- https://discuss.px4.io/t/hard-fault-when-switching-comms-link/47382
- https://github.com/PX4/PX4-Autopilot/issues/12502
- https://github.com/PX4/PX4-Autopilot/issues/19798
- https://github.com/PX4/PX4-Autopilot/issues/12502
- https://github.com/PX4/PX4-Autopilot/issues/22239
- https://github.com/PX4/PX4-Autopilot/issues/24436
Eventually, we still need to refactor the threading mess, of course.
I wish I could answer your questions. It happens enough to come up again and again, last with 1.15.4, so it might be fixed in the meantime.
And I couldn't reproduce it on the bench yet, unfortunately. I tried for a few hours. That being said, I think the fixes are not wrong, and won't make it worse.
This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:
https://discuss.px4.io/t/hard-fault-when-switching-comms-link/47382/12