Skip to content

fix: atomic saves for prefs, ACL, regions and companion blobs - #3254

Draft
benallfree wants to merge 1 commit into
meshcore-dev:devfrom
MeshEnvy:feature/atomic-fs-save
Draft

fix: atomic saves for prefs, ACL, regions and companion blobs#3254
benallfree wants to merge 1 commit into
meshcore-dev:devfrom
MeshEnvy:feature/atomic-fs-save

Conversation

@benallfree

@benallfree benallfree commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Hey guys I noticed that config writes currently truncate-then-write in place, which can risk losing prefs on a crash or failure. This PR makes those saves atomic write-rename instead.

Let me know what you think.

Co-authored-by: Cursor <cursoragent@cursor.com>
@liamcottle

liamcottle commented Aug 20, 2026

Copy link
Copy Markdown
Member

Unfortunately this doesn't fix the issue on nRF boards using LittleFS due to differences between file system block size and page erase sizes.

@oltaco and I spent significant time digging into the lower level stuff to resolve this, but ultimately it requires changes at the LittleFS level.

You'll find that even with atomic writes, you'll still get file system corruption, or file loss during power off due to nRF erasing more blocks than LittleFS expects.

Can be tested by saving preferences in app, and powering off the node while it's writing. Which would be a similar scenario as battery going flat while receiving/saving an advert payload to contacts database.

@oltaco

oltaco commented Aug 20, 2026

Copy link
Copy Markdown
Member

Yep, @liamcottle is correct. The fix will be this #2964, I haven't had a single corruption with LFSv2.

@benallfree

Copy link
Copy Markdown
Contributor Author

@liamcottle @oltaco Thank you for looking into this more. In #3012 I mentioned LFSv2 as a possible solution, it's great to learn that it is already underway.

@benallfree

Copy link
Copy Markdown
Contributor Author

Just for clarity...this PR is not about FS corruption though. Currently there is a short window where prefs are deleted and new prefs have not been written.

Is there any value to the write-rename vs delete-write? I still see a possibility where all prefs can get lost without filesystem corruption.f

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.

3 participants