Repository navigation
all: Prevent directory undeletion on macOS 14.3+ when syncXattrs is enabled (fixes #9371) - #9424
luckman212 wants to merge 1 commit into
Conversation
|
I'm personally not convinced it's either of the named root issues. As the main issue seems to be, from what I see in logs, that the modification time adjusts right before we want to delete the directory involved on the receiving side -> every time at the same moment it seems, a bit too coincidental. Followed, later on, by a propagation of this directory as And the walker later on (please note the mod time/inode change time); The modification time of the local dir changed somewhere between the Stat->Delete logic, it could be some external event - or our xattr-handling (perhaps of the child-files) does something tricky to the directories involved.. Not sure how to figure that part out though. Edit: actually, deleting a file inside a folder also has effect on the folder's mod/inode time. Which, perhaps, we only really care for when syncing xattrs (as folders tend to be a bit of a special case, they usually don't have too much content to keep in sync), just a thought. |
|
Thanks @er-pa. The inode change time of the dir itself getting touched when deleting a child object does seem to correlate with the issue. I don't know why that would only be something new for OS 14.3 though. I did my best to try to capture low level filesystem events in realtime (most of my notes on that are here) but it didn't lead to anything enlightening. The workaround proposed here still fits, does it not? |
|
Well, yes and no. That would mean that it's not a platform bug (just an oversight from our side) and will affect any platform. Why it wasn't detected before is a bit unknown. But I can replicate it with two instances on a single Bookworm host too (non-virtual). In that case we may just have to conclude that the mod-time and inode-time for directories are relatively useless and we'll just have to rely on detecting differences in either the ownerships or xattrs when figuring out whether they're equal. So practically your approach, just a tiny tweak; a bit more general. But perhaps a more knowledgeable one can give some input on this as I may oversee something. (p.s., I didn't really check any code (style/..), just what it intends to solve:)) |
|
@er-pa Actual code changes were pretty minimal. But I am definitely interested that you were able to replicate this on stock Debian (no macOS involved). So, perhaps the platform check should be removed altogether and we simply ignore inode modtime changes on dirs altogether. The xattrs still sync during rescans in my testing, with folder colors/labels/and spotlight metadata comments. edit: I spun up 2 Debian 12.5.0 VMs and installed Syncthing 1.27.3 on both of them. I then created a sync folder In light of this finding, I'm inclined to revise the PR so it extends to all platforms, but I'm going to pause here and wait for @calmh or @imsodin to weigh in. |
|
Caring about directory modification time while we are processing deletes is certainly a bug, we should expect it to change all the time without any significance for us. I don't know whether the same goes for the directory inode change time; intuitively I think it should not change due to deleting a child item, but I also don't think it's well defined in any case... |
|
Thanks for looking @calmh. Right, as I understand it,
I agree then, when processing directory deletes, these metadata should not be considered. Are we on the right track with the PR I submitted here? (if we widen the scope to include other OS'es). If not, would these be the areas to focus on? syncthing/lib/model/folder_sendrecv.go Lines 544 to 555 in f4d1606 syncthing/lib/model/folder_sendrecv.go Lines 809 to 850 in f4d1606 syncthing/lib/model/folder_sendrecv.go Lines 1939 to 1964 in f4d1606 |
|
For someone who doesn't know Go (and iexperienced with the codebase), I do have to say I am impressed with your work in both documenting and still trying a solution. Even if the original solution was inadequate, your work has been more thorough than what I would ever expect from any end user. I have been following the issue, since you reported it, and I am genuinely impressed. Documenting a problem, trying a fix in a language you don't even write in, several screen recordings, and multiple days of non-stop work for a project you don't even own or maintain. Well done, sir. 👏 |
|
I wonder if we should ever care about a metadata difference when deleting something. The behaviour we have now is designed for files, with the intention that a metadata change (modtime, size, etc) may indicate a change to the actual data, and we don't want to delete a file that's been changed and not synced. For directories this isn't a thing, and I don't think changes to things like xattrs should block a delete either, really. Maybe we just need to special case the delete for directories to ignore changes to metadata even when syncing xattrs... |
|
@calmh I'm fiddling around with this. Would something like this work (basically short circuit if !cf.IsEquivalentOptional(diskFile, protocol.FileInfoComparison{
ModTimeWindow: f.modTimeWindow,
IgnorePerms: f.IgnorePerms,
IgnoreBlocks: true,
IgnoreFlags: protocol.LocalAllFlags,
IgnoreOwnership: !f.SyncOwnership,
IgnoreXattrs: info.IsDir() || !f.SyncXattrs,
}) {edit: never mind that^^ |
|
I'll let others decide over the best approach for the fix as it's not something I know a lot about, yet. However, I did backtrack it to the change which introduced this behaviour, as it may be good to know:); |
|
Thanks @er-pa for that find. Still surprised at how little attention this is getting—seems the people who've noticed it can be counted on one hand. Ok then, seems we are waiting for Jakob to weigh in. Regardless, #9430 is more likely to be an acceptable solution, so this PR should probably be closed and the conversation continued over there. |
Closed as requested 🙂. |
Purpose
This is my attempt at fixing (fix may be a strong word, more of a workaround) the "deleted folder snapback" issue described in great lengths at #9371. I have limited experience with the Syncthing codebase, and with Go in general, so this really needs some more 👀 !
I believe the root cause of this "bug" is either:
syncthingbinary to properly set the folder modification timestamps (even when granted Full Disk Access TCC/PPPC permissions)—or—
The result is the directory inode modtimes in the db become "out of sync" with what later gets read back from the filesystem. This causes hysteresis when a folder is deleted: the receiving side thinks it's been changed and forces a rescan, defers the deletion, which is then picked up by the sender, and the folder is "put back" (sans all contained files however...)
Testing
I tried to take a conservative approach—this only targets macOS for now (not sure if this issue is confirmed to occur on other platforms). I added a bit of debug logging.
Tested on:
syncthingbinary replacing the one from the app bundle (based on1.27.4-rc1+ 3e8ec95)go1.22.0In addition to many hours of manual testing, I ran the following simple shell script, which repeatedly creates a folder, dumps some files into it, and then deletes the folder—over and over. Before this patch, the
xyzzyfolder would almost immediately snap back on Mac-A.When run with the
STTRACEenv var set e.g.STTRACE=all, you will see log entries like the one below when this code path is hit: