qgroundcontrol: QGC crashes when sending Vehicle MAVLink message on a link! (at unexpected times)
I would like to bring to your notice that QGC crashes at unexpected times when using Serial/or multiple links. I recently figured out why and where this happens and the root cause. The culprit is the way we have written the function priorityLink() and its usage while sending mavlink messages.
If AutoConnect UDP is used, there will be at least one link in the Vehicle::_links Qlist. When the serial USB is connected, there is this serial link. What this logic of priorityLink() does is it gives Serial the priority and if it is not found, the first link in the _links list is returned.
/// @return Direct usb connection link to board if one, NULL if none
LinkInterface* Vehicle::priorityLink(void)
{
foreach (LinkInterface* link, _links) {
if (link->isConnected()) {
SerialLink* pSerialLink = qobject_cast<SerialLink*>(link);
if (pSerialLink) {
return link;
}
}
}
return _links.count() ? _links[0] : NULL;
}
Two problems:
-
return _links.count() ? _links[0] : NULL; When no vehicle is connected, we disable the QGC GUI - so we are safe. But during certain heavy processing, like sending a big mission to the vehicle, if the link (serial/other) is disconnected - the above could/is certainly NULL. Consequences? Crash of QGC, as we use prioritylink()->mavlinkChannel() while sending each message. Access on NULL instance!
-
If there are more than 1 links (apart from serial, say a UDP and a TCP i.e. Serial, UDP, TCP in the list) for the same vehicle (which is allowed) - which link must be chosen if Serial is not available? The first in the list after Serial, i.e. UDP -> does not make much sense. This indicates the TCP link will never be used.
Somehow it feels to me that the implementation of PriorityLink() is incomplete. Suggest to at least place a NULL check apart from link not being connected while sending ANY Mavlink message to the vehicle.
PS: Also, notice that isConnected() for UDP link will never be ‘false’ (unless user disconnects manually) and isConnected() for Serial will usually not occur (as the link object is lost immediately on a disconnect).
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 18 (13 by maintainers)
No null checks where removed. The position where you need to call LinkInterface::mavlinkChannel changed. Used to be in a single place behind a null check in Vehicle:sendMessage. Now it needs to be in all the *_pack_chan mavlink channels which are all of the codebase.
The mavlink 2.0 changes are new and have not yet been released to stable version.
That is not what happens on Windows OS. On Windows you don’t lose the connection when you pull the plug on usb cable. The serial port is still there and connected, it’s just in a zombie state. Hence you need to connectionLostTimeout as well to make things work across all OS.
For #2 you can’t tell the difference between a temporary loss of communication with a vehicle and/or the vehicle was just turned off/disconnected in all cases across of OS. Hence the connectionLossTimeout which then notifies the user and lets them disconnect manually if they want. If the users decides to manually disconnect that is when the Vehicle goes away.
All of the above is correct behavior.
Dual links are pretty standard - e.g. a radio module and Wifi. People use them to retain command & control if the main link fails. That said QGC is lacking a suitable QoS mechanism. The firmware side on the other hand has it.
Why this works in practice is that QGC does not send a whole lot of data and the Firmware side QoS takes care of scalability. Which makes dual links extremely useful for development and industrial applications, which is the only fields where QGC really is reasonably strong as a tool right now.
Or in other words - relevant and used.
Well, it’s a bit more than a patch. There are 81 references to
priorityLink()and none of those calls ever check to see if the link is NULL. That is something that needs addressing. No call that receives a pointer should ever blindly use it, without checking for NULL first, no matter how remote the chances for a NULL are. With that said, it IS remote as it can only happen on corner cases. Yes, it should be fixed but how often are you connected to a vehicle with two or more links?I never liked that whole dual link thing to begin with but I understand the need to handle it. The entire link system became a patch work over the years. I will patch it but we should start thinking about rethinking the whole link model.
The way I see it, when you plug something using a USB cable, you are doing firmware maintenance. Nothing else should be connected. That’s the only time you end up with dual links, which I think should not be allowed at all.