-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mavlink: Fixed command sender race condition #12560
Conversation
@@ -172,7 +172,7 @@ void MavlinkCommandSender::check_timeout(mavlink_channel_t channel) | |||
} | |||
} | |||
|
|||
if (item->num_sent_per_channel[channel] < max_sent) { | |||
if (item->num_sent_per_channel[channel] < max_sent && item->num_sent_per_channel[channel] != -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't exactly understand this one. Why would it still be -1
?
As discussed with @bkueng : If a command in the queue receives an ack, set the field "num_sent_per_channel" to -2 but leave the command in the queue. When we reach the timeout for that command we only re-send the command if "num_sent_per_channel" is not -2. |
Yes essentially the changes here are good (hardening the logic), but don't solve the race condition. The same command is still inserted several times. To resolve it we can wait for at least 1 timeout before removing commands from the list. |
- if we receive an ack for a command through a specific mavlink channel then do not drop the corresponding command in the queue if this specific mavlink channel did not issue the command. If we don't do this we can end up in a situation where we associate an ack coming through a specific mavlink channel to a command in the queue which was not requested by this mavlink channel. Moreover, the actual command for which the ack was meant remains in the queue and eventually triggers a timeout. Signed-off-by: RomanBapst <bapstroman@gmail.com>
did not request this command Signed-off-by: RomanBapst <bapstroman@gmail.com>
- if a channel receives an ack for a command, do not immediately remove the command item from the send queue but wait until the next ack timeout occurs. This gives other mavlink channels time to try to put identical commands into the send queue. Signed-off-by: RomanBapst <bapstroman@gmail.com>
559d247
to
9a41d27
Compare
@bkueng I updated based on your suggestion. Could you please review again. I verified basic functionality. |
@@ -147,6 +146,23 @@ void MavlinkCommandSender::check_timeout(mavlink_channel_t channel) | |||
continue; | |||
} | |||
|
|||
// Loop through num_sent_per_channel and check if any channel has receives an ack for this command | |||
// (indicated by the value -2). We avoid removing the command at the time of receiving the ack | |||
// as some channels might be lagging behind and will end up putting the same command into the buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well explained.
This is an attempt to fix #12553
See commit message for further explanation.
This fixes irregular camera trigger messages. I'm not aware if there is something I'm breaking with this change, e.g. if there was a particular reason why the current behavior is as is.