Skip to content

Smarter subtree pruning when walking with ignore exclusions #6681

Description

@intelfx

(Please refer to https://forum.syncthing.net/t/completely-prevent-syncthing-from-traversing-a-directory-subtree/15060 for context.)

problem

Consider the following .stignore:

// .stignore.work -- ignore all except "work" (unique files and work-critical configuration)
!/Documents
!/devel
!/.gitconfig.*
!/.profile.*
!/.kube
!/.config/gcloud
!/.stignore.*
*

When enabling filesystem watching, Syncthing Web UI displays the following error:

Filesystem Watcher Errors

For the following folders an error occurred while starting to watch for changes. It will be retried every minute, so the errors might go away soon. If they persist, try to fix the underlying issue and ask for help if you can't.

error  while traversing  /home/intelfx/.local/share/containers/storage/btrfs/subvolumes/05fadaaa4dcce2b1a1ca001bd1512826d5df49fd7495cf6a4495b219e27d4294/var/cache/apt/archives/partial:  permission denied

Additionally, this causes Syncthing to permanently hog 100% CPU, apparently spent in repeated attempts to set up inotify for ~/.local (a huge directory tree). In this configuration, Syncthing should not attempt to look into ~/.local at all.

(This problem goes away when the !/.config/gcloud include pattern is removed from .stignore.)

feature request

This feature request is about making .stignore parser smart enough to prune ignored subtrees from all further processing even in presence of complex include statements.

Alternatively, there could be an overriding "priority ignore" list that will exclude specific directories from any and all further processing, disregarding all other rules.

what problem your new feature would solve

excessive CPU usage when using complex whitelist-style .stignore configurations in presence of very large and potentially inaccessible (ignored) subtrees

how or why you think it is generally useful (i.e., not just for you)

directories are sometimes ignored for a reason — Syncthing should not even attempt to access them, potentially burning many cycles and energy on constrained devices

what alternatives or workarounds you considered

workaround rationale
removing non-toplevel include patterns from .stignore I can live without .config/gcloud, but obviously this kind of solution is not always possible
configuring the OS to hide problematic directories from Syncthing (e. g. via configuring InaccessiblePaths= in systemd unit or otherwise utilizing mount namespaces) this requires root access to the system which is not always present or convenient

Activity

  1. added
    enhancement
    needs-triage
    on May 25, 2020
  2. AudriusButkevicius commented on May 25, 2020

    @AudriusButkevicius
    Member

    My gut says there already exists an issue for this. Have you done a search before opening this?

  3. intelfx commented on May 25, 2020

    @intelfx
    Author

    @AudriusButkevicius Yes, I did a cursory search for "stignore" and "include" in open issues and didn't see anything that would catch my eye. I could be wrong, of course.

    The closest I know to my issue is #6072 which deals with a specific side effect rather than the general idea of better ignores handling.

  4. AudriusButkevicius commented on May 25, 2020

    @AudriusButkevicius
    Member

    To be honest, I think it's the same thing, in terms of what the implementation will have to do, so I feel we should close this.

  5. intelfx commented on May 25, 2020

    @intelfx
    Author

    @AudriusButkevicius Is it? #6072 can be fixed with masking permission errors from the watcher, which does not solve the underlying issue of spending cycles on an ignored subtree. What if one of the ignored subtrees was a networked FUSE filesystem with complex semantics?

  6. AudriusButkevicius commented on May 25, 2020

    @AudriusButkevicius
    Member

    I don't think we really care about fuse filesystems with complex semantics.

    We assume a normal filesystem, and at the moment you start introducing something fancy like encfs or whatever, it becomes your problem, not ours.

  7. changed the title [-]RFE: do not traverse ignored directories in presence of non-toplevel .stignore includes[/-] [+]Smarter subtree pruning when walking with ignore exclusions[/+] on Aug 31, 2020
  8. calmh commented on Aug 31, 2020

    @calmh
    Member

    I think this is a valid issue, even if just as an optimization. Currently our optimization is quite simple. If we had a function to answer the question "can anything underneath this subtree ever match any of the exclude patterns" then we could avoid walking & watching those subtrees.

  9. removed
    needs-triage
    on Aug 31, 2020
  10. AudriusButkevicius commented on Aug 31, 2020

    @AudriusButkevicius
    Member

    But how is this different from #6072 so that we let it live?

  11. calmh commented on Aug 31, 2020

    @calmh
    Member

    It isn't, but that one looks like it's all about handling permissions issues, while this one is clearer. This one lives, that one dies, I clean up this one.

  12. nalt commented on Sep 1, 2020

    @nalt

    100% CPU also means increased power consumption and constant disk activity. With this behaviour you cannot really run syncthing as a background daemon. So this issue should be more than an enhancement.
    It seems that the external watcher didn't have this problem, after issue 161 has been fixed. Could any insight be taken from there?

  13. calmh commented on Sep 1, 2020

    @calmh
    Member

    I think we fixed too-fast watcher retries a while back?

  14. added theissue type on May 30, 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

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions