Skip to content

notify file watcher: don't follow symlinks - #1642

Open
simonmar wants to merge 1 commit into
meta:mainfrom
simonmar:notify-no-follow-symlinks
Open

simonmar wants to merge 1 commit into
meta:mainfrom
simonmar:notify-no-follow-symlinks

Conversation

@simonmar

Copy link
Copy Markdown

Summary

With the default notify file watcher, the daemon can stop noticing changes
in a directory that a symlink inside the project also leads to. Builds then
use stale sources until the daemon is restarted.

The watcher watches the project recursively with notify's default config,
which follows symlinks. inotify has one watch per directory, however many
paths lead to it: adding a watch for a directory that is already watched
returns the same watch descriptor. notify keeps one path for each
descriptor, the one it walked last. So if the project has link -> a and
notify walks link after a, every later event in a is reported under
link. A change to a/f arrives as a change to link/f. Nothing depends on
link/f, because buck2 reads through a symlink by its target's own path, so
DICE keeps its old copy of a/f.

Whether a directory is affected depends on the order of the initial walk,
so it looks random to users. Restarting the daemon fixes it, because a new
daemon reads everything again. notify 9 still keeps one path per descriptor,
so the update to 9.0.0-rc.6 doesn't change this.

This change turns off follow_symlinks, so each directory is watched only by
its own path. A symlink's target inside the project is watched where it is.
Watchman doesn't follow symlinks either, so both watchers now behave the
same. A side effect is that the watcher no longer watches directories outside
the project that symlinks point to. buck2 never acted on those events, since
it doesn't track changes behind external symlinks.

Reproduction

mkdir -p repro/a repro/zz && cd repro
printf '[cells]\nroot = .\n[buildfile]\nname = BUCK\n' > .buckconfig
cat > defs.bzl <<'EOF'
def _cat_impl(ctx):
    out = ctx.actions.declare_output("out")
    ctx.actions.run(cmd_args("sh", "-c", 'cat "$1" > "$0"', out.as_output(), ctx.attrs.src), category = "cat")
    return [DefaultInfo(default_output = out)]
cat = rule(impl = _cat_impl, attrs = {"src": attrs.source()})
EOF
printf 'load("//:defs.bzl", "cat")\ncat(name = "t", src = "a/y.txt")\n' > BUCK
echo v1 > a/y.txt
ln -s ../a zz/a
buck2 build //:t --out -     # v1
echo v2 > a/y.txt
buck2 build //:t --out -     # still v1; the event log shows a change to zz/a/y.txt

We hit this in GHC's source tree. Its configure links two library
directories into another package's directory, so edits to one of those
libraries were missed until buck2 kill.

Test plan

  • New test change_behind_symlink_is_reported_under_real_path, for Linux.
    It watches a directory with 16 symlinks to it, changes a file in the
    directory, and checks that the event names the file's real path. With
    with_follow_symlinks(true) it fails every time, and the change is
    reported as links2/a/f.
  • cargo test -p buck2_file_watcher --lib notify: all 6 tests pass.
  • The reproduction above, with a buck2 built from this branch: the second
    build prints v2, and the event log shows a change to a/y.txt.

🤖 Generated with Claude Code

The notify watcher watched the project with notify's default config, which
follows symlinks. inotify has one watch per directory, however many paths
lead to it, and notify reports a directory's events under whichever of
those paths it walked last. So with a symlink `link -> a`, a change to
`a/f` could be reported as a change to `link/f`. Nothing depends on
`link/f`, because buck2 reads a symlink's target by the target's own path,
so the daemon kept its stale copy of `a/f` until it was restarted.

Each directory is now watched only by its own path, as watchman does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 20, 2026
@meta-codesync

meta-codesync Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D133488702. (Because this pull request was imported automatically, there will not be any future comments.)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant