Skip to content

Syncthing incorrectly deletes file on sync #6293

Closed as not planned
Closed as not planned

Description

@genericmoniker

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

  1. Create a new note in Notable (Notable will call this file "Untitled.md" at first).
  2. Change the title of the note to "Syncthing test" (The file is now "Syncthing test.md")
  3. Make a few edits.
  4. Change focus away from Notable, which will cause it to flush edits to disk using the delete/move pattern.
  5. Repeat 3-4 a few times.
  6. Wait for Syncthing to synchronize (seemed to be a couple of minutes).
  7. 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

  1. calmh commented on Jan 25, 2020

    @calmh
    Member

    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,watchaggregator should show precisely what Syncthing thinks about the file at the source at least.

  2. genericmoniker commented on Feb 22, 2020

    @genericmoniker
    Author

    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:

    Date & Time:	2/22/2020 9:56:09 AM
    Event Class:	File System
    Operation:	SetRenameInformationFile
    Result:	SUCCESS
    Path:	D:\Users\Eric\Documents\Sync\Notes\notes\Syncthing test.md
    TID:	12468
    Duration:	0.0051208
    ReplaceIfExists:	True
    FileName:	D:\Users\Eric\Documents\Sync\Notes\.stversions\notes\Syncthing test~20200222-095609.md
    

    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:

    procmon

  3. imsodin commented on Apr 13, 2020

    @imsodin
    Member

    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:

    Reproducing it with STTRACE=fs,scanner,watchaggregator should show precisely what Syncthing thinks about the file at the source at least.

  4. added
    waiting-for-info
    on Apr 13, 2020
  5. masenocturnal commented on Aug 18, 2020

    @masenocturnal

    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.

  6. masenocturnal commented on Aug 18, 2020

    @masenocturnal

    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.

  7. masenocturnal commented on Aug 18, 2020

    @masenocturnal

    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.

  8. added
    frozen-due-to-age
    on Apr 9, 2025
  9. locked and limited conversation to collaborators on Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frozen-due-to-agewaiting-for-info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions