Skip to content
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

Merged
merged 4 commits into from
Aug 5, 2019
Merged

Mavlink: Fixed command sender race condition #12560

merged 4 commits into from
Aug 5, 2019

Conversation

RomanBapst
Copy link
Contributor

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.

@RomanBapst RomanBapst requested review from julianoes and bkueng July 26, 2019 11:54
@RomanBapst RomanBapst changed the title Pr mavlink race Mavlink: Fixed command sender race condition Jul 26, 2019
@@ -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) {
Copy link
Contributor

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?

@RomanBapst
Copy link
Contributor Author

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.

@bkueng
Copy link
Member

bkueng commented Jul 30, 2019

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>
@RomanBapst
Copy link
Contributor Author

@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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well explained.

@bkueng bkueng merged commit 43d006a into master Aug 5, 2019
@bkueng bkueng deleted the pr-mavlink_race branch August 5, 2019 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mavlink command sender race condition
3 participants