From 1279772d92dc3bbe86a4f32abb8c9d3a6c14f1ee Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Jun 2021 11:33:25 +1000 Subject: [PATCH] AP_Logger: disallow log creation in main thread when armed this fixes an issue where the sd card fails in flight and then re-mounts. When that happens the logging backend can trigger a new log open. That causes filesystem operations in the main thread while flying. That can cause long delays or even a watchdog. Thanks to Giacomo for noticing this on his flying wing --- libraries/AP_Logger/AP_Logger_File.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/AP_Logger/AP_Logger_File.cpp b/libraries/AP_Logger/AP_Logger_File.cpp index ddc9ca73ea..3df650d923 100644 --- a/libraries/AP_Logger/AP_Logger_File.cpp +++ b/libraries/AP_Logger/AP_Logger_File.cpp @@ -435,6 +435,17 @@ bool AP_Logger_File::StartNewLogOK() const if (recent_open_error()) { return false; } + if (hal.scheduler->in_main_thread() && + hal.util->get_soft_armed() && + AP_HAL::millis() - hal.util->get_last_armed_change() > 3000) { + // when we create the log while arming we are armed and the + // creation is in the main loop. We generally don't want to + // allow logs to start in main thread while armed, but we + // have an exception for the first 3s after arming to allow + // for the normal arming process to work. This can be removed + // when we move log creation to the logging thread + return false; + } return AP_Logger_Backend::StartNewLogOK(); }