Skip to content

Windows file-watcher panics: ignore crate 'path is expected to be under the root' #37

Description

@hrabbach

Summary

On Windows, the file-watcher (watch_directory) panics on a tokio-rt-worker thread on a regular basis with:

thread 'tokio-rt-worker' (40024) panicked at C:\Users\runneradmin\.cargo\registry\src\cache.avrea.com-e45b643e7c84d5cb\ignore-0.4.25\src\gitignore.rs:232:9:
path is expected to be under the root

The panic is caught by tokio so the server keeps running, but it recurs while a directory is watched (and the offending file event is presumably dropped, so that save may not get incrementally re-indexed).

Environment

  • memtrace: 0.7.25 (npm global)
  • OS: Windows 11
  • Dependency: ignore 0.4.25 (gitignore.rs:232)

Suspected cause

Looks like a Windows path-prefix mismatch. Indexed repos are stored with the extended-length \\?\ prefix (e.g. \\?\C:\Users\...\repo), but the watch was registered / events arrive with the plain C:\Users\...\repo form. When the Gitignore matcher is rooted with one prefix form and asked to match a path in the other, strip_prefix(root, path) fails and the crate panics with "path is expected to be under the root".

Suggested fix

Canonicalize Windows paths to a single prefix form before feeding them to the ignore crate (make the gitignore root and the incoming event path agree), and/or wrap the gitignore match in catch_unwind so a mismatch degrades to "no match" instead of a worker-thread panic.

Repro

  1. Index a repo on Windows (path gets stored with \\?\ prefix).
  2. watch_directory on the plain C:\... path.
  3. Save files in the repo — panic recurs.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions