Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/model: Newly created conflicting files can be silently overwritten #3742

Closed
mpx opened this issue Nov 18, 2016 · 5 comments
Closed

lib/model: Newly created conflicting files can be silently overwritten #3742

mpx opened this issue Nov 18, 2016 · 5 comments
Labels
bug A problem with current functionality, as opposed to missing functionality (enhancement) frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Comments

@mpx
Copy link
Contributor

mpx commented Nov 18, 2016

Syncthing overwrote a conflicting file during a sync without noticing the conflict.

I expected Syncthing to notice the file it was about to overwrite had not yet been seen through a local scan and either rename it, or create the new file with a "conflict" filename.

Syncthing Version: v0.4.11 both sides
OS Version: Windows 10 / FreeBSD 9.3 / Fedora 24

Steps:

  1. Add a new file X on machine A (Windows 10).
  2. Add a new file X on machine B (FreeBSD 9.3) with different content.
  3. Rescan on machine A. Triggers sync to machine B.

Machine B overwrites file X without warning since it hasn't discovered it via a scan yet.
I've tested this between a few different OSes in different directions.
Other observations:

  • Modifying existing files on both sides before a single rescan appears to work correctly.
  • Deleting the test files then rescanning/recreating on both sides/rescanning appears to generate the expected conflict file.

It is slightly contrived I know, but it is more likely when using longer rescan intervals to conserve battery / IOPS. There is no safety net if multiple machines create a file with the same name within a rescan interval.

@AudriusButkevicius
Copy link
Member

Yeah it causes a bunch of other issues too, I think we already have an issue for this (or atleast relating to this).

@calmh
Copy link
Member

calmh commented Nov 18, 2016

I think we check for unexpected conflicts on files we know exist, but not for files we don't know exist.

@calmh calmh added the bug A problem with current functionality, as opposed to missing functionality (enhancement) label Nov 18, 2016
@calmh calmh added this to the Unplanned (Contributions Welcome) milestone Nov 18, 2016
@Ferroin
Copy link

Ferroin commented Nov 18, 2016

Just looking at this, a couple of thoughts come up:

  • This is probably significantly less likely to impact people using file change notifications on the receiving system because syncthing-inotify (or whatever other tool) is likely to notify Syncthing of the new file pretty quickly (much smaller race window).
  • Fixing this would require adding a check on the receiving end that the destination file doesn't already exist. Ideally, that check should happen just before we rename the temporary file into place after downloading everything. Such a check would slow down synchronization (you have to get a directory listing after each file downloaded.
  • Because of both of the above factors, if this does get implemented, it should be done in a way that it can be disabled at runtime, as some users won't ever have this issue (I would actually expect most people to not have this issue).

@calmh
Copy link
Member

calmh commented Nov 18, 2016

I don't think it needs to be that bad. We need to to a stat before replacing, which we already do if the destination file is in the index (i.e., almost always).

There will still be a window between us checking and the rename actually happening, but that's at least down to the millisecond range.

@Ferroin
Copy link

Ferroin commented Nov 18, 2016

Ah, I actually hadn't known Syncthing calls stat() just before replacing the destination file. If that's the case, then that pretty much negates my argument about performance (and thus the argument for this being configurable).

@calmh calmh changed the title Newly created conflicting files can be silently overwritten puller: Newly created conflicting files can be silently overwritten Nov 23, 2016
@calmh calmh changed the title puller: Newly created conflicting files can be silently overwritten lib/model: Newly created conflicting files can be silently overwritten Jan 23, 2017
liusy182 added a commit that referenced this issue Jul 21, 2017
always use `currentFolderFile()`'s version which is more up-to-date than
cached version in `sendReceiveFolder` struct
AudriusButkevicius added a commit to AudriusButkevicius/syncthing that referenced this issue Aug 21, 2017
viable-hartman pushed a commit to viable-hartman/syncthing that referenced this issue Aug 25, 2017
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Sep 10, 2018
@syncthing syncthing locked and limited conversation to collaborators Sep 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug A problem with current functionality, as opposed to missing functionality (enhancement) frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

No branches or pull requests

5 participants