next.js
4ade2cf4 - Turbopack: Watch parent directories before watching children in `non_recursive_helpers::start_watching_dir_and_parents` (#82454)

Commit
234 days ago
Turbopack: Watch parent directories before watching children in `non_recursive_helpers::start_watching_dir_and_parents` (#82454) Fixes a potential race condition https://github.com/vercel/next.js/pull/82130#discussion_r2249131891: > I think there is a race condition here, when the child dir is created while we are walking the parent directories. > > 1. we try to watch /path/to/dir but it doesn't exist. > 2. /path/to/dir is created > 3. we move to the parent directory (`path/to`) and start watching it. > 4. But we already missed the event that path/to/dir was created. > > I think we need to run the loop reverse direction, watching parent directories first before watching the child directories. This way we already have the parent directory watcher setup before "reading" the child directory (reading in the sense of starting to watch it). Tested by putting a `println!()` in `start_watching_dir` and observing that the parents were watched first when running ``` rm -rf /tmp/fuzz && cargo run -p turbo-tasks-fuzz -- fs-watcher --fs-root /tmp/fuzz ```
Author
bgw bgw
Parents
Loading