fix(px4_work_queue): don't touch a WorkItem after its Run() returns (#29278) (#29531)

Modules that stop through ModuleBase::exit_and_cleanup() delete themselves
inside Run(), and since 9b62a1701d WorkQueue::Run() then clears
_run_in_progress in the freed object. ASAN aborts SITL on
`battery_simulator stop` and the stop of most other work queue modules.

Track the in-flight item in the WorkQueue instead, which lives until its
own Run() exits on the worker thread.

Assisted-by: Claude:claude-opus-5-5
(cherry picked from commit 8c5f4e0788)
This commit is contained in:
Jacob Dahl authored and GitHub committed 2026-10-31 10:24:52 -06:00
1 parent 5f5a2d11ef
commit cc28d51849
4 files changed
+15 -10

No files matched your search

+3 -3
View File
@@ -104,10 +104,10 @@ void WorkItem::Deinit()
// and corrupts the hrt callout queue.
//
// Skip the wait if we're being called from inside Run() on the
// worker thread itself (e.g. should_exit() → ScheduleClear),
// which would deadlock against our own flag.
// worker thread itself (e.g. should_exit() → exit_and_cleanup),
// which would deadlock waiting on ourselves.
if (!pthread_equal(pthread_self(), wq_temp->runner_tid())) {
while (_run_in_progress.load()) {
while (wq_temp->is_running(this)) {
px4_usleep(100);
}
}