Skip to content

[BUG] Multiple mutex lock().unwrap() calls crash the file watcher on poisoned locks #111

@Cute0110

Description

@Cute0110

Project

vgrep

Description

Multiple calls to .lock().unwrap() on mutex can panic if the mutex is poisoned (another thread panicked while holding the lock), crashing the entire file watcher process.

Error Observation

If any thread panics while holding the mutex, subsequent lock attempts will panic, causing a cascading failure.

Error Message

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PoisonError { .. }'

Debug Logs

System Information

Version: 0.1.0

## Operating System
  OS: Ubuntu 24.04.3 LTS
  Kernel: 6.8.0-79-generic
  Arch: x86_64

## Hardware
  CPU: AMD Ryzen 9 5950X 16-Core Processor (4 cores)
  RAM: 11 GB

## Build Environment
  Rust: rustc 1.92.0 (ded5c06cf 2025-12-08)
  Target: x86_64

Screenshots

No response

Steps to Reproduce

  1. Open src/watcher.rs
  2. Examine lines 104-105, 111, 118, 142:
let should_process = {
    let last = last_process.lock().unwrap();     // Can panic!
    let pending = pending_files.lock().unwrap(); // Can panic!
    !pending.is_empty() && last.elapsed() >= debounce_duration
};

### Expected Behavior

Should use `.unwrap_or_else(|e| e.into_inner())` to recover from poisoned mutexes.

### Actual Behavior

A panic in any thread holding these mutexes will crash the file watcher, requiring manual restart.

### Additional Context

This is a known Rust anti-pattern for production code. 5 instances at lines 104, 105, 111, 118, 142.

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