Skip to content

fix: release database lock during file I/O in cleanup_deleted#286

Closed
laynepenney wants to merge 1 commit intomainfrom
feat/fix-lock-contention
Closed

fix: release database lock during file I/O in cleanup_deleted#286
laynepenney wants to merge 1 commit intomainfrom
feat/fix-lock-contention

Conversation

@laynepenney
Copy link
Copy Markdown
Collaborator

Summary

Fixes lock contention issue identified in PR #285 code review.

Problem

In cleanup_deleted(), the database lock was held during file system operations:

let db_lock = db.lock().await;  // Lock acquired
for file_path in indexed_files {
    if !full_path.exists() {  // Blocking I/O under lock
        db_lock.delete_file(file.id)?;
    }
}

This blocks other operations from accessing the database during file system checks.

Solution

Refactored to release the lock during file I/O:

  1. Get indexed files (lock held briefly)
  2. Collect paths to delete (no lock - file system checks)
  3. Delete files (lock held briefly per operation)

Changes

  • codi-rs/src/symbol_index/indexer.rs - Refactored cleanup_deleted()

Verification

  • Zero build warnings
  • All 516 tests pass
  • Clean build

Related

- Collect file paths first (no lock)
- Only acquire lock briefly for delete operations
- Avoids blocking file system checks under lock
- Zero warnings, all 516 tests pass
@laynepenney
Copy link
Copy Markdown
Collaborator Author

Closing this PR. After further review, the lock contention 'fix' is unnecessary - the original code from PR #285 is acceptable for a manual maintenance operation. The 'fix' introduced redundant queries and unnecessary complexity for a theoretical problem that doesn't exist in practice.

@laynepenney laynepenney closed this Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant