Fix spiLock deadlocks / frequent watchdog restarts in WarmNodeStore::save() (#10809)
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
co-authored by
GitHub
Ben Meadors
parent
0488a46a3c
commit
b44ed4552f
@@ -354,10 +354,16 @@ void MessageStore::clearAllMessages()
|
||||
resetMessagePool();
|
||||
|
||||
#ifdef FSCom
|
||||
concurrency::LockGuard guard(spiLock);
|
||||
SafeFile f(filename.c_str(), false);
|
||||
uint8_t count = 0;
|
||||
f.write(&count, 1); // write "0 messages"
|
||||
|
||||
// SafeFile already does its own spiLock in its constructor and close().
|
||||
// Avoid nesting spiLocks, as this will hang until watchdog reset!
|
||||
{
|
||||
concurrency::LockGuard guard(spiLock);
|
||||
f.write(&count, 1); // write "0 messages"
|
||||
}
|
||||
|
||||
f.close();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -589,12 +589,22 @@ bool WarmNodeStore::save()
|
||||
h.entrySize = sizeof(WarmNodeEntry);
|
||||
h.crc = crc32Buffer(packed.data(), h.count * sizeof(WarmNodeEntry));
|
||||
|
||||
concurrency::LockGuard g(spiLock);
|
||||
FSCom.mkdir("/prefs");
|
||||
// SafeFile already does its own spiLock in its constructor and close().
|
||||
// Avoid nesting spiLocks, as this will hang until watchdog reset!
|
||||
|
||||
{
|
||||
concurrency::LockGuard g(spiLock);
|
||||
FSCom.mkdir("/prefs");
|
||||
}
|
||||
|
||||
auto f = SafeFile(warmFileName, false);
|
||||
f.write((const uint8_t *)&h, sizeof(h));
|
||||
f.write((const uint8_t *)packed.data(), h.count * sizeof(WarmNodeEntry));
|
||||
|
||||
{
|
||||
concurrency::LockGuard g(spiLock);
|
||||
f.write((const uint8_t *)&h, sizeof(h));
|
||||
f.write((const uint8_t *)packed.data(), h.count * sizeof(WarmNodeEntry));
|
||||
}
|
||||
|
||||
bool ok = f.close();
|
||||
if (!ok)
|
||||
LOG_ERROR("WarmStore: can't write %s", warmFileName);
|
||||
|
||||
Reference in New Issue
Block a user