You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(metrics): render_prometheus deadlock if self.fallback_rate called inside threading.Lock #254
ProductMetrics.render_prometheus() acquires self._lock and snapshots values inline rather than calling self.fallback_rate (the property). This is an undocumented defensive pattern: self._lock is a non-reentrant threading.Lock, so calling self.fallback_rate inside the lock would deadlock. Any future refactor that replaces the inline computation with self.fallback_rate will ship a production deadlock under concurrent Prometheus scraping.
Root Cause
backend/app/productization/metrics.py around line 134:
withself._lock:
# snapshot values manually — cannot call self.fallback_rate here# because fallback_rate property also acquires self._lock → deadlockrouting_count=self.routing_countfallback_count=self.fallback_countfallback_rate=fallback_count/routing_countifrouting_countelse0.0# inline
The fallback_rate property acquires self._lock. render_prometheus also holds self._lock. Non-reentrant lock → deadlock. The current code avoids this by duplicating the computation inline, but there is no comment explaining why, making the constraint invisible to future contributors.
Failure Scenario
Developer adds: fallback_rate = self.fallback_rate inside render_prometheus()'s with self._lock: block.
Prometheus scraper calls /metrics concurrently with a routing request calling record_routing().
render_prometheus acquires self._lock, then attempts self.fallback_rate which tries to acquire self._lock again.
Deadlock. The /metrics endpoint hangs forever. The routing request is also blocked on self._lock.
Worker appears healthy (no crash) but all requests queue behind the deadlocked lock.
Proposed Fix
Switch to threading.RLock (reentrant lock) to make the property callable from within the lock:
Activity
piyushmakhija28 commentedon Jun 21, 2026
Fixed in PR #280 (Sprint R3/R4: fix(sprint-r3): root-cause fixes for all 39 bugs from code review round 3 + Sprint R4 round 4)