Skip to content

evict an outgoing peer that closed before the cache published it - #777

Merged
cheggaaa merged 1 commit into
mainfrom
cheggaaa/fix-pool-evict-preload
Sep 1, 2026
Merged

evict an outgoing peer that closed before the cache published it#777
cheggaaa merged 1 commit into
mainfrom
cheggaaa/fix-pool-evict-preload

Conversation

@cheggaaa

@cheggaaa cheggaaa commented Sep 1, 2026

Copy link
Copy Markdown
Member

Not a regression from this release train — the structure dates to 08f8d6d3 (PR #693, go-7301-quic-pool-eviction, 2026-06-01) and has shipped since v0.12.6. #773 made one consequence newly visible by adding the KindClosed notification to evictOnClose.

The outgoing watcher is started from inside the ocache load func, before the value is published. RemoveSame deliberately never matches a still-loading entry — its comment is explicit that matching a nil value would wait the load out and close whatever the load publishes. So a connection dying in that window meant:

  • the watcher's RemoveSame returned ErrNotExists and the watcher exited, leaving the closed peer to be published with no watcher at all — it lingered until the next Get self-healed it or the TTL reaped it;
  • the observer reported KindClosed for a peer the pool had not yet accepted (no preceding KindConnected).

Waiting the load out via Pick before removing fixes both, and keeps the existing "never close a live replacement" invariant: RemoveSame still only removes this exact peer, so if another value took the id nothing happens. Incoming peers are published synchronously by AddPeer, so that path removes without a wait and is untouched.

TestPool_EvictsOutgoingClosedDuringLoad drives the seam directly — a load held open while the peer closes — and fails without the fix (closed peer must not stay cached after the load publishes).

go test -race ./net/pool/... green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HXNxMzxa6rK3bAwcULTt4x

The outgoing watcher starts inside the ocache load func, before the value is
published, and RemoveSame deliberately never matches a still-loading entry
(a nil value would wait the load out and close whatever it publishes). A
connection dying in that window left the closed peer published with no watcher
left to evict it, so it lingered until the next Get self-healed it or the TTL
reaped it, and the observer reported Closed for a peer the pool had not
accepted.

Wait the load out before removing. Incoming peers are published synchronously
by AddPeer, so that path keeps removing without a wait.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

New Coverage 61.8% of statements
Patch Coverage 100.0% of changed statements (2/2)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

@requilence
requilence self-requested a review September 1, 2026 17:00
@cheggaaa
cheggaaa merged commit e3f5a90 into main Sep 1, 2026
4 checks passed
@cheggaaa
cheggaaa deleted the cheggaaa/fix-pool-evict-preload branch September 1, 2026 17:09
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants