fix(FileManager): SD log pruning caused stack-canary panic on MQTT connect task
Confirmed on hardware: enabling SD logging at INFO level caused a boot loop within seconds — "Guru Meditation Error... Stack canary watchpoint triggered (mqttConnect)". appendLogLine() was running pruneLogDirectory() (a full SD.open() directory scan + std::vector<pair<String,size_t>> build) on every single log write, and the first write happened to land on MQTTDriver's 3KB-stack connect task. Fixes: - Prune check now throttled to once per 50 writes instead of every write — removes the expensive directory scan from the hot logging path entirely. - Bumped mqttConnect/mqttRecon/mqttHB task stacks from 3072 to 4096 bytes as defense-in-depth, since these tasks can still trigger SD log writes. - Removed a LOG_INFO call inside pruneLogDirectory that could have re-entered Logging::writeToSd() from within the SD write path itself.
This commit is contained in:
@@ -86,6 +86,13 @@ private:
|
||||
bool ensureDirectoryExists(const String& dirPath);
|
||||
String logFileNameForTimestamp(time_t timestamp) const;
|
||||
void pruneLogDirectory(const String& logDir, size_t maxTotalBytes);
|
||||
|
||||
// pruneLogDirectory() does a full directory scan (SD.open + iterate every
|
||||
// file) — too expensive to run on every single log line, and the calling
|
||||
// task's stack may not have room for it (e.g. the 3KB MQTT connect task).
|
||||
// Only check every LOG_PRUNE_CHECK_INTERVAL writes.
|
||||
static constexpr uint16_t LOG_PRUNE_CHECK_INTERVAL = 50;
|
||||
uint16_t logWriteCountSinceProbe = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user