Skip to content

get_recent_screenshots holds two mutex locks and does IO under them #18

@codehakase

Description

@codehakase

Description

get_recent_screenshots (src-tauri/src/lib.rs:544-573) acquires both HistoryState and ThumbnailState mutexes simultaneously, then performs file existence checks and image thumbnail generation (file IO + image decoding + base64 encoding) while holding both locks:

let history = history_state.lock().unwrap();
let thumbnail_gen = thumbnail_state.lock().unwrap();

for screenshot in recent_screenshots {
    // file I/O + image processing while holding both locks
    let thumbnail_base64 = if Path::new(&screenshot.file_path).exists() {
        thumbnail_gen.get_thumbnail_base64(...)
    } ...
}

Impact

  • Any other Tauri command needing either mutex (e.g., save_to_disk, delete_screenshot) will block until all thumbnails are generated.
  • With 10 screenshots and cache misses, this could take several seconds, freezing the UI for other operations.

Suggested fix

Clone the screenshot list while holding the history lock, drop it, then generate thumbnails with only the thumbnail lock (or better, move thumbnail generation to a non-locking async task).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions