Skip to content

[repo-health] Medium: Mutex poisoning panics in SqliteStorage — lock().unwrap() crashes worker threads #11

@Liohtml

Description

@Liohtml

Summary

SqliteStorage::store() and retrieve() call self.conn.lock().unwrap() without handling mutex poisoning, causing all worker threads to panic if any single thread panics while holding the storage lock.

Category

Bug

Severity

Medium

Location

  • File: src/core/storage.rs
  • Line(s): 41, 55

Details

If any thread panics while holding the Mutex<Connection> lock, all subsequent calls to lock() return a PoisonError. Calling .unwrap() on a poisoned mutex causes a panic in every caller, bringing down the entire crawler engine even if the original failure was transient or isolated to one spider task.

In a concurrent crawl context (CrawlerEngine spawns many tasks), this means a single bad page can crash storage for all subsequent requests.

Suggested Fix

Use .lock().unwrap_or_else(|e| e.into_inner()) to recover the inner value from a poisoned mutex, or return an error:

// Before
let conn = self.conn.lock().unwrap();

// After (recovery)
let conn = self.conn.lock().unwrap_or_else(|e| e.into_inner());

// Or (propagate as error)
let conn = self.conn.lock().map_err(|_| StorageError::LockPoisoned)?;

Effort Estimate

15 min


Automated finding by repo-health-agent v1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions