Repository navigation
cl/sentinel: build one peers.Pool for the whole test package - #23847
Conversation
Every peers.NewPool starts two TTL-cache cleanup goroutines, and the upstream expirable LRU never closes their done channel, so they run for the rest of the process. The fixture built a pool per test, leaving eight behind per suite repetition and growing with the size of the package. Share one pool. Each test creates its own hosts, so peer IDs are disjoint and ban state cannot carry between them, and nothing in this package reaches Pool.Request, the only method that uses the host. Measured with a temporary probe counting surviving cleanup goroutines: eight per repetition before, a flat two after, at -count=1, 2 and 3. Follow-up to #23606.
| NoDiscovery: true, | ||
| }}, | ||
| peers: peers.NewPool(local), | ||
| peers: testPeerPool(), |
There was a problem hiding this comment.
Non-blocking: this changed callsite is not covered by TestFixtureReusesOnePeerPool. Reverting it to peers.NewPool(local) leaves the new regression test green while reintroducing two cleanup goroutines per discovery-test run. Could we route this fixture through one shared builder, or assert here that sentinel.peers is testPeerPool(), so the package-wide guarantee cannot regress silently?
| func (s stubP2P) UpdateENRAttSubnets(subnetIndex int, on bool) {} | ||
| func (s stubP2P) UpdateENRSyncNets(subnetIndex int, on bool) {} | ||
|
|
||
| // testPeerPool is shared package-wide because every peers.NewPool starts two TTL-cache cleanup |
There was a problem hiding this comment.
Non-blocking: the repository comment policy asks us not to encode callsite inventories because they become stale. The statement about Pool.Request is also the safety condition for using a nil-host pool. Could this be phrased as the invariant instead, for example that the shared fixture is only for sentinels that do not perform host-backed peer requests?
domiwei
left a comment
There was a problem hiding this comment.
The test-only change materially reduces leaked TTL-cache cleanup goroutines, and the focused plus race tests pass. I left two non-blocking comments about pinning the discovery callsite against regression and expressing the nil-host safety condition as an invariant.
…23847)" This reverts commit 57811e9. The pool was shared because every peers.NewPool started two ttl-cache cleanup goroutines that could not be stopped. The ttl cache no longer starts a goroutine, so a pool per test leaks nothing, and the shared fixture, its comments and its pin test have no reason left.
Follow-up to #23606, addressing @domiwei's second non-blocking review comment.
Every
peers.NewPoolstarts two TTL-cache cleanup goroutines, and the upstream expirable LRUnever closes their
donechannel —Close()is commented out in the dependency with a notethat it will only arrive after v2. The goroutines therefore run for the rest of the process.
The
cl/sentinelfixture built a pool per test, so the count grew with the size of the package.Share one pool instead. It is safe because each test creates its own hosts, so peer IDs are
disjoint and ban state cannot carry between tests, and nothing in this package reaches
Pool.Request— the only method that uses the host.Measured with a temporary probe counting surviving cleanup goroutines: eight per suite
repetition before, a flat two after, at
-count=1,2and3.TestFixtureReusesOnePeerPoolpins the arrangement; restoring the per-test pool fails it.Removing the ban read from
handleNewConnectionstill failsTestBannedPeerIsClosedInsteadOfHandshaked, so the shared pool has not weakened the tests itcarries. Package passes with
-shuffle=on(three runs) and under-raceat-count=2;make lintclean.Test-only change, so no new coverage beyond the pin above.
Not addressed here: production code has the same unstoppable-goroutine property, but every
call site is a process-level singleton, so nothing leaks at runtime. Making
lru.CacheWithTTLclosable would need us to own the expiry sweep —
expirable'sGetalready checksExpiresAt,so the background goroutine only reclaims memory — and it would touch consensus-adjacent caches.
Filed separately rather than folded in here.