Repository navigation
Description
I'm using Notable to create/edit Markdown note files in a Syncthing synchronized folder. I've noticed several cases recently while creating and editing a new note that Syncthing appears to delete the note. I expected the note to continue to exist, and be synchronized to other devices instead of being deleted.
I suspect this might be because of the save pattern that Notable uses. It creates a temporary file, writes to it, deletes the original file, then moves the temp file to the original file's location. I think this is a fairly common pattern for applications.
Steps
- Create a new note in Notable (Notable will call this file "Untitled.md" at first).
- Change the title of the note to "Syncthing test" (The file is now "Syncthing test.md")
- Make a few edits.
- Change focus away from Notable, which will cause it to flush edits to disk using the delete/move pattern.
- Repeat 3-4 a few times.
- Wait for Syncthing to synchronize (seemed to be a couple of minutes).
- Syncthing deletes "Syncthing test.md".
I've only noticed this happening on Windows, where it has happened on two separate machines. I regularly use Linux as well and haven't seen this there.
Here is the log output of a file watcher (watchmedo from the Python watchdog package):
on_created(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileCreatedEvent: src_path='.\\Untitled.md.2744387218'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Untitled.md.2744387218'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Untitled.md.2744387218'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Untitled.md.2744387218', dest_path='.\\Untitled.md'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Untitled.md'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Untitled.md', dest_path='.\\Syncthing test.md'>)
on_created(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileCreatedEvent: src_path='.\\Syncthing test.md.1871265359'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.1871265359'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.1871265359'>)
on_deleted(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileDeletedEvent: src_path='.\\Syncthing test.md'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Syncthing test.md.1871265359', dest_path='.\\Syncthing test.md'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md'>)
on_created(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileCreatedEvent: src_path='.\\Syncthing test.md.2777820927'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.2777820927'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.2777820927'>)
on_deleted(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileDeletedEvent: src_path='.\\Syncthing test.md'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Syncthing test.md.2777820927', dest_path='.\\Syncthing test.md'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md'>)
on_created(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileCreatedEvent: src_path='.\\Syncthing test.md.1459320582'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.1459320582'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.1459320582'>)
on_deleted(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileDeletedEvent: src_path='.\\Syncthing test.md'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Syncthing test.md.1459320582', dest_path='.\\Syncthing test.md'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md'>)
on_created(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileCreatedEvent: src_path='.\\Syncthing test.md.1061029909'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.1061029909'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.1061029909'>)
on_deleted(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileDeletedEvent: src_path='.\\Syncthing test.md'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Syncthing test.md.1061029909', dest_path='.\\Syncthing test.md'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md'>)
on_created(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileCreatedEvent: src_path='.\\Syncthing test.md.2843975383'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.2843975383'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md.2843975383'>)
on_deleted(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileDeletedEvent: src_path='.\\Syncthing test.md'>)
on_moved(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileMovedEvent: src_path='.\\Syncthing test.md.2843975383', dest_path='.\\Syncthing test.md'>)
on_modified(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileModifiedEvent: src_path='.\\Syncthing test.md'>)
on_deleted(self=<watchdog.tricks.LoggerTrick object at 0x000001D14430D898>, event=<FileDeletedEvent: src_path='.\\Syncthing test.md'>)
For the last logged FileDeletedEvent, I didn't do anything that I would expect to delete the file. I believe it to be Syncthing itself that decided it needed to be deleted. The UI reports "Latest Change Deleted Syncthing test.md".
I also tried the same set of steps in a folder not being synchronized, and the file didn't get deleted unexpectedly.
Version Information
Syncthing Version: v1.3.3
OS Version: Windows 10
Activity
calmh commentedon Jan 25, 2020
This clearly requires investigation. I'll just add though that the file watcher events don't directly drive what Syncthing thinks happened to a file. The events just mark names in the filesystem for investigation, and a regular scan will then look at the file to decide what the change actually was. If it's not present at the time we look at the file that will be sent out as a delete, of course. That should however be an extremely unlikely sequence of events given the short amount of time (presumably) the file spends being deleted, and would anyway not result in the file being deleted at the source. In short, no idea what's going on here, needs reproduction.
Reproducing it with
STTRACE=fs,scanner,watchaggregatorshould show precisely what Syncthing thinks about the file at the source at least.genericmoniker commentedon Feb 22, 2020
Is it possible this has something to do with file versioning?
I used sysinternals procmon (Process Monitor) to try to get a better idea of what process was doing file operations on my disappearing note. I'm not super-proficient at interpreting procmon, but the sequence of operations I see indicates that Notable creates the note, syncthing accesses it, Notable edits the note, syncthing saves a version, Notable tries to read the note again and it is not found.
Of interest is this operation done by the syncthing.exe process:
If I'm reading that correctly, syncthing renames/moves the original file into .stversions rather than copying it?
Here's a procmon screen shot with that operation in context:
imsodin commentedon Apr 13, 2020
File versioning kicks in on remote changes. So if this (versioning) happens during the problem you describe above, there is interaction with a remote involved. Can you reproduce without any remotes connected?
And please provide these logs:
masenocturnal commentedon Aug 18, 2020
I have also lost my recent changes to files overwritten with the state on the remote machine. 1.8.0 on Ubuntu. It's clearly syncing some (most) of my files correctly but I've lost about 6 hours worth of work on a markdown document and it's repopulated the folder with a bunch of files (images, documents) which I deleted on that night. The updates were the first in many weeks to that folder.
masenocturnal commentedon Aug 18, 2020
Not sure if this helps, but there were additional files in the directory which were not present on the remote which are now just completely gone.
masenocturnal commentedon Aug 18, 2020
Further update......I haven't lost the files....they are sitting on the remote system but not my local system (where the changes were made). It's like they have switched places. The remote system is a headless box at my parents house so it's not like I could have in any way made the changes on the other machine without knowing. Completely odd but I'm very happy at least the other end has my files.