Skip to content

I156: GIL held across commit fsyncs and Argon2id passphrase rotate_key — freezes all Python threads #144

Description

@Xof

Migrated from ISSUES.md, which was retired in favour of GitHub issues. Original id I156, priority P3, from the 2026-07-02 deep review (docs/reviews/review-20260702-001902.md).

The text below is the triaged entry verbatim, including the corrections triage made to the original finding.


Where: python/src/db.rs:652

Problem: Per-op engine calls (including commit's 3 fsyncs, defrag, and add_key/rotate_key/remove_key) hold the GIL for their full duration; only open() detaches (db.rs:276). With passphrase keys, rotate_key runs Argon2id (19 MiB, t=2) once or twice under the GIL — roughly 100-300 ms, not seconds — freezing all other Python threads. The GIL-hold is an explicitly documented design tradeoff (db.rs:634-651 names the consequence and both fix paths), but that comment predates the encryption work (2026-06-20 vs PR #85), so the memory-hard KDF case was never weighed; the comment should at least be updated to name key ops alongside commit/defrag. A passphrase rotate_key or a large commit freezes every other Python thread in the process for the full KDF/fsync duration — seconds-scale for Argon2id. The encryption work postdates the 'per-op calls hold the GIL' comment, which was reasoned about quick engine ops, not a deliberately slow memory-hard KDF.

Direction of fix: Move the mutex acquisition inside py.detach (detach → lock → engine call → unlock → reattach); the closure only needs Chisel: Send, which open() already proves. Do NOT detach while holding the guard — that inverts the GIL/Mutex order and can deadlock. At minimum, detach around the three key-management methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:performanceHot paths, allocation, measurement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions