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

mavsdk_server: fix crash on stop/destruction #2417

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

julianoes
Copy link
Collaborator

This fixes a segfault which happens when the mavsdk_server is stopped and destroyed before every having discovered any autopilot.

What happened is that:

  1. ConnectionInitiator would be cancelled.
  2. ConnectionInitiator would be destructed.
  3. And only now the connect thread would wake up from sleeping and read the _should_exit flag which at this point has been destroyed. At this point the connect function would try to access Mavsdk::systems() which is also destructed by that point and cause a segfault.

The fix is to wrap the ConnectionInitiator class in a shared ptr and keep that one alive in the connect function to avoid destruction until it has returned.

This fixes a segfault which happens when the mavsdk_server is stopped
and destroyed before every having discovered any autopilot.

What happened is that:
1. ConnectionInitiator would be cancelled.
2. ConnectionInitiator would be destructed.
3. And only now the connect thread would wake up from sleeping and read
   the _should_exit flag which at this point has been destroyed.
   At this point the connect function would try to access
   Mavsdk::systems() which is also destructed by that point and cause a
   segfault.

The fix is to wrap the ConnectionInitiator class in a shared ptr and
keep that one alive in the connect function to avoid destruction until
it has returned.
Copy link

sonarcloud bot commented Oct 6, 2024

Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

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

Nice catch! 🚀

@julianoes julianoes merged commit 8a4bfde into v2.12 Oct 6, 2024
32 checks passed
@julianoes julianoes deleted the pr-v2.12-fix-server-teardown branch October 6, 2024 18:28
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.

2 participants