fix: bound the peer relay connection cache with LRU eviction - #207
Open
thexeos wants to merge 1 commit into
Open
Conversation
RemoteManager cached one connection per (url, addr) peer and only ever dropped an entry when that connection died, so a relay that talks to many peers over its lifetime accumulated pooled QUIC connections without limit — each with its own keep-alive — for the life of the process. Give the pool a configurable capacity (RelayTuning::max_remote_connections, default 256, 0 disables) with least-recently-used eviction. Recency is refreshed on cache hits as well as insertion, and eviction only reclaims entries nothing is using: a subscriber holds a use guard for as long as its upstream subscription lives, and an entry with a live guard — or whose slot lock is held by an in-flight connect or teardown — is skipped rather than closed, so the pool may sit over capacity instead of cutting off a live subscription. Candidate slots are probed with try_lock while the pool lock is held, so the existing pool/slot lock order is unchanged and no lock is held across an await.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #202 to draft-14. On this branch the knob rides the existing
RelayTuning, so no public signature changes.RemoteManagerkeeps one cached connection per(url, addr)peer and only drops an entry when that connection dies, so a relay that talks to many peers over its lifetime accumulates pooled QUIC connections without limit, each with its own keep-alive, for the life of the process. This adds a configurable capacity (default 256,0disables) with least-recently-used eviction, refreshing recency on cache hits as well as insertions. Eviction only reclaims connections that nothing is using — every caller holds a use guard while it is subscribed, publishing or forwarding over a connection, and an entry with a live guard (or a slot lock held by an in-flight connect) is skipped rather than closed, so a full pool of busy peers stays over capacity instead of cutting off a live subscription. No new dependencies; the LRU is a linear scan over a few hundred entries, run only when a new connection is added.