Skip to content

core: Fix data race in mission transfer WorkItem dtor#2792

Merged
julianoes merged 3 commits intomainfrom
pr-tsan-cancel
Mar 12, 2026
Merged

core: Fix data race in mission transfer WorkItem dtor#2792
julianoes merged 3 commits intomainfrom
pr-tsan-cancel

Conversation

@julianoes
Copy link
Collaborator

Use unregister_all_blocking() instead of unregister_all() in WorkItem destructors to wait for any in-flight message handler callbacks to complete before destroying the object. The non-blocking variant uses try_to_lock which can fail if a callback is executing, causing use-after-free when the destructor proceeds to deallocate members.

Should fix thread sanitizer issue which happened in https://github.com/mavlink/MAVSDK/actions/runs/22841268305/job/66247808660?pr=2790.

Use unregister_all_blocking() instead of unregister_all() in WorkItem
destructors to wait for any in-flight message handler callbacks to
complete before destroying the object. The non-blocking variant uses
try_to_lock which can fail if a callback is executing, causing
use-after-free when the destructor proceeds to deallocate members.
JonasVautherin
JonasVautherin previously approved these changes Mar 11, 2026
Defer WorkItem destruction to after releasing the LockedQueue mutex.
The WorkItem destructor calls unregister_all_blocking() which acquires
the message handler mutex, while process_message() holds the message
handler mutex and can push_back() to the queue - causing a deadlock
cycle.
Add mutex to protect _system_ids unordered_set which was being
concurrently read by has_system_id() (work thread) and written to
by receive_message() (UDP receive thread).
@julianoes julianoes merged commit 952c461 into main Mar 12, 2026
54 checks passed
@julianoes julianoes deleted the pr-tsan-cancel branch March 12, 2026 14:15
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