oliver-zehentleitner / maity

hub: Keep the Why: one counted per-key lock helper instead of four hand-written ones (ktw.Cache, ForeignCache, slots, flights)

Sign in to report

tsk-984ce6mqbn3r Open

Audit round 3b (tsk-hgnbapyw7hnh), read at 80fef076. Kind: duplication.

What is wrong

  • Four hand-written "a lock per key, counted while a call holds or waits for it, dropped by the last user": hub/src/maity_hub/ktw.py:783-845 (Cache.locks/users/_enter/_leave/_lock), hub/src/maity_hub/ktw_reads.py:117-147 (ForeignCache.get, slot [lock, callers]), ktw_reads.py:239-262 (_slots/_slot/_free), ktw_reads.py:266-269 and :321-339 (_flights/_one_read). Each has its own guard and its own copy of release-on-last-user.

Proposal

  • One small keyed_lock helper with a context manager (acquire with timeout or non-blocking, count, drop on last exit); the semaphore variant takes a factory.

Effort / risk: S-M. Medium: concurrency code; test_keep_the_why_views and test_keep_the_why_attacks must stay green.