Skip to content

[BUG] Race Condition in File Deletion Handling #90

@olddev94

Description

@olddev94

Project

vgrep

Description

The process_files() function in src/watcher.rs lines 301-313 has a time-of-check to time-of-use (TOCTOU) race condition. A file could be deleted between the path.exists() check and the subsequent read_to_string() call, causing silent failures where deleted files remain in the index.

Error Message

No error message - silent failure to remove deleted files from index.

Debug Logs

System Information

- Bounty Version: 0.1.0
- OS: Ubuntu 24.04 LTS
- Rust: 1.75+

Screenshots

No response

Steps to Reproduce

  1. Start file watcher: vgrep watch
  2. Create a script that rapidly creates and deletes files:
    while true; do
      echo "test" > /tmp/project/temp_file.rs
      rm /tmp/project/temp_file.rs
    done
  3. Run the script while watcher is active
  4. Observe that some deleted files may remain in the index

Expected Behavior

When a file read fails due to deletion:

  1. Check if the file was deleted
  2. If deleted, remove from index
  3. Log the race condition for debugging

Actual Behavior

  1. File deletion between check and read is silently ignored
  2. Deleted file remains indexed
  3. Searches may return results pointing to non-existent files

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingideIssues related to IDEinvalidThis doesn't seem rightvgrep

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions