Fix race condition in LRUCache with thread safety improvements#8
Fix race condition in LRUCache with thread safety improvements#8Karticoder wants to merge 2 commits into
Conversation
|
@Karticoder CI tests are failing — check the CI. |
|
I’m not convinced yet that this change is correct for sigflow’s architecture, and I have a few concerns before this can move forward. The main issue is that the PR assumes
Right now the tests mostly stress concurrent access and verify “no exception occurred”, but they do not demonstrate a concrete failing invariant or regression in the current implementation. I’m also concerned about the scope of the change:
Please split the worker pool ordering change into a separate PR if it is intentional. Additionally, the new class docstring and PR description overstate the impact a bit. Phrases like:
need stronger justification and reproducible evidence before we can classify this as a real vulnerability rather than a theoretical concurrency hardening improvement. Before I can consider merging this, please provide:
|
|
@jmestwa-coder I have updated |
|
@Karticoder follow the previous message and update this PR |
Summary
Implemented a thread-safety fix for
sigflow/cache/lru.pyby protecting shared cache state with athreading.Lock.This prevents concurrent
get(),set(), and__len__()operations from corrupting the internalOrderedDict, eliminating a race condition that could lead to inconsistent cache state, stale reads, or unexpected eviction behavior under multi-threaded workloads.Root Cause
LRUCacheaccessed and modified shared mutable state without synchronization.Because
OrderedDictoperations and eviction logic were executed concurrently across threads, interleaved reads/writes could produce:The cache implementation assumed single-threaded access, but no enforcement or synchronization existed.
Security Impact
This patch hardens the cache implementation against concurrent state corruption and race conditions.
Without synchronization, attackers or malformed workloads could trigger nondeterministic behavior in multi-threaded environments, potentially causing:
Changes Made
sigflow/cache/lru.py