Skip to content

Back off retries when file watch registration keeps failing - #62489

Open
etiennechatreaux wants to merge 3 commits into
zed-industries:mainfrom
etiennechatreaux:fs-watcher-retry-backoff
Open

Back off retries when file watch registration keeps failing#62489
etiennechatreaux wants to merge 3 commits into
zed-industries:mainfrom
etiennechatreaux:fs-watcher-retry-backoff

Conversation

@etiennechatreaux

Copy link
Copy Markdown

Objective

Part of #62486: when watch registration keeps failing (in that issue, FSEvent stream creation failing after fd exhaustion on macOS), poll_path_until_created retries the same path every 2 seconds forever — no backoff, no cap. On an already-degraded process this spams the log (267 warnings in the 10 minutes before log rotation killed the log) and keeps hammering a resource that is already exhausted.

This does not fix the watcher leak that causes the exhaustion in the first place (see the retention chain posted on the issue); it stops the retry loop from making a degraded process worse. Related: #59571 takes a complementary route for the same error signature (classifying the macOS FSEvent failure into the native watch-limit cooldown); this PR bounds the per-path retry loop itself, for any registration error on any platform.

Solution

Double the retry delay after each failed registration attempt, capped at 60 seconds. The base interval stays poll_interval() (2s by default), so the common case — polling for a path that doesn't exist yet — is unchanged, and the first sleep is identical to before. The delay only grows on the Err arm, and the warning now says when the next retry happens.

To make the failure path testable, the registration function is now a parameter of poll_path_until_created (it previously called register_existing_path directly, which goes through the global_watcher() static, so a fake backend couldn't be injected into the poll task).

Testing

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Improved file watcher error handling to back off exponentially when watch registration keeps failing, instead of retrying every 2 seconds forever.

poll_path_until_created retried a failing registration at the base poll
interval (2s) forever, spamming the log and hammering an already-degraded
process (see the fd exhaustion in zed-industries#62486). Double the delay after each
failed attempt, capped at 60s; the create-poll cadence is unchanged.
@cla-bot

cla-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @etiennechatreaux on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Aug 11, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 11, 2026
@dinocosta dinocosta added the area:scanning Worktree scanning related PRs. label Aug 13, 2026
`TestAppContext::executor()` already returns a `BackgroundExecutor` by
value, so the extra `.clone()` tripped `-D clippy::redundant-clone` on
every clippy_* CI job for the fs lib test target.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LKrrp8U9ptLJTYM6kujA1Y
@etiennechatreaux

Copy link
Copy Markdown
Author

The clippy_* failures were a redundant_clone in the new test (cx.executor().clone()TestAppContext::executor() already returns a BackgroundExecutor by value). Fixed in 3d1a549.

Verified locally with the CI command on the pinned toolchain (./script/clippy -p fs, rustc 1.97.1): clean, and fs_watcher::tests still 16/16. The new workflow runs are waiting for approval.

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

Labels

area:scanning Worktree scanning related PRs. cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants