I have an Obsidian vault I share between two iOS devices, a Windows machine, a FreeBSD machine (TrueNAS), and a Linux machine. With no clear pattern, sometimes (every month or so) I open some file to find it has been turned into NULL bytes (literal zeroes). This is pretty upsetting, but before I resort to buying a closed-source service, I wanted to give troubleshooting a try. How can I track down this bug and find the source next time it happens? My log files don’t go back far enough for me to find out what it was.
I’ve heard of this happening with a certain access pattern for the creating application (i.e, obsidian in his case). If the app pre-creates a file by truncating to the correct size and Syncthing is triggered by a notification, it will read and sync a file that is all zeroes. If the application then writes the content in-place without modifying the timestamp, Syncthing can’t know that the file has changed again.
I don’t know if Obsidian does this, but if so a workaround could be to increase the delay before acting on file system notifications in Syncthing.
If the the file is a memory mapped database of some sort (e.g., sqlite) you will likely see issues like this as writing to an mmapped file won’t bump the modification time. (Until it’s closed, iirc)
Obsidian’s “vaults” (a folder/directory) where notes are stored are mostly text files (Markdown syntax) along with any attachments (e.g. images, PDF), so no databases the last time I checked.
One potential wrinkle is that while a Markdown file is being edited, Obsidian saves updates every other second.
Are the corrupted files only recently edited files?
Do the file sizes change? (i.e. Every character is replace 1:1 with a zero?)
Is it only one file every month or so, or does it affect bunches of files at a time?
If the problem is randomly occurring without any clear pattern, reviewing Syncthing’s logs with debugging features enabled might be quite a chore given the time span involved.
If I was faced with the same problem, with just 5 device, I’d try to narrow the scope by disabling Syncthing on one device and waiting to see of the problem disappears. If the problem still exists, re-enable Syncthing and repeat on the next untested device. By process of elimination the source of the problem will be revealed.