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

[BACKPORT v2.12] core: prevent lockup on connection destruction #2412

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

julianoes
Copy link
Collaborator

Backport of #2411.

When we destroy Mavsdk and clear the list of connections, we likely
end up in a deadlock.

What happens is that:
1. A connection wants to forward a message and is trying to acquire the
   connection mutex.
2. At the same time, the connection is being destroyed, so we are
   waiting for the connection receive thread to be joinable. While the
   connections are being destroyed, we have the connection mutex which
   is blocking 1.

The proposed solution is to:
1. Make it less likely by acquiring the connection mutex properly before
   checking _connections.size() and not for the individual connections.
2. Check the _should_exit flag before trying to acquire the mutex. I
   believe by the time the connections are being cleared, this flag is
   set, and hence the deadlock should not happen, fingers crossed.
Copy link

sonarcloud bot commented Oct 3, 2024

@julianoes julianoes merged commit f8fbc03 into v2.12 Oct 3, 2024
31 checks passed
@julianoes julianoes deleted the pr-v2.12-fix-connection-cleanup branch October 3, 2024 03:17
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.

1 participant