Skip to content

fix(appproxy): make circuit locks self-cleaning to prevent unbounded growth#12873

Draft
seedspirit wants to merge 1 commit into
mainfrom
fix/appproxy-coordinator-circuit-lock-leak
Draft

fix(appproxy): make circuit locks self-cleaning to prevent unbounded growth#12873
seedspirit wants to merge 1 commit into
mainfrom
fix/appproxy-coordinator-circuit-lock-leak

Conversation

@seedspirit

Copy link
Copy Markdown
Contributor

Summary

  • Replace CircuitManager._circuit_locks (plain dict) with a weakref.WeakValueDictionary so a per-circuit lock entry lives exactly as long as some coroutine holds or waits on it, then vanishes with its last user
  • Fixes unbounded memory growth in Traefik mode: the 30s reconcile loop registers a lock entry for every live circuit, but entries were only removed by unload_circuits() in the same process — HA setups (reconcile consumed by instance A, unload run by instance B) and missed-unload circuits leaked entries forever
  • Also fixes a mutual-exclusion race: the old explicit pop could orphan a lock that still had waiters, letting a subsequent caller create a second lock for the same circuit and enter the critical section concurrently

Test plan

  • pants test tests/unit/appproxy/coordinator:: — all pass
  • New tests: lock entry self-cleans after its last user; pending waiters keep the entry alive and concurrent callers converge on the same lock object
  • mypy / ruff clean on changed files

🤖 Generated with Claude Code

…growth

Replace CircuitManager._circuit_locks with a WeakValueDictionary so a
lock entry lives exactly as long as some coroutine holds or waits on it.

The previous dict grew without bound in Traefik mode: the 30s reconcile
loop created an entry for every live circuit, but entries were only
removed by unload_circuits() in the same process, so HA setups and
missed-unload circuits leaked entries forever. The explicit pop also
orphaned locks that still had waiters, breaking per-circuit mutual
exclusion when a new caller created a second lock for the same circuit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:L 100~500 LoC comp:app-proxy Related to App Proxy component labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:app-proxy Related to App Proxy component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant