Skip to content

cl/sentinel: build one peers.Pool for the whole test package - #23847

Merged
lystopad merged 1 commit into
mainfrom
lystopad/sentinel-test-pool-goroutines
Sep 7, 2026
Merged

lystopad merged 1 commit into
mainfrom
lystopad/sentinel-test-pool-goroutines

Conversation

@lystopad

@lystopad lystopad commented Sep 7, 2026

Copy link
Copy Markdown
Member

Follow-up to #23606, addressing @domiwei's second non-blocking review comment.

Every peers.NewPool starts two TTL-cache cleanup goroutines, and the upstream expirable LRU
never closes their done channel — Close() is commented out in the dependency with a note
that it will only arrive after v2. The goroutines therefore run for the rest of the process.
The cl/sentinel fixture 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, 2 and 3.

TestFixtureReusesOnePeerPool pins the arrangement; restoring the per-test pool fails it.
Removing the ban read from handleNewConnection still fails
TestBannedPeerIsClosedInsteadOfHandshaked, so the shared pool has not weakened the tests it
carries. Package passes with -shuffle=on (three runs) and under -race at -count=2;
make lint clean.

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.CacheWithTTL
closable would need us to own the expiry sweep — expirable's Get already checks ExpiresAt,
so the background goroutine only reclaims memory — and it would touch consensus-adjacent caches.
Filed separately rather than folded in here.

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(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 domiwei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lystopad
lystopad added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit 57811e9 Sep 7, 2026
143 checks passed
@lystopad
lystopad deleted the lystopad/sentinel-test-pool-goroutines branch September 7, 2026 20:23
yperbasis added a commit that referenced this pull request Sep 22, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Caplin Caplin: Consensus Layer, Beacon API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants