fix(autorelay): track the disconnected peer cleanup goroutine - #3522
Open
Sahil-4555 wants to merge 1 commit into
Open
Sahil-4555 wants to merge 1 commit into
Sahil-4555 wants to merge 1 commit into
Conversation
Sahil-4555
force-pushed
the
fix/query-relay-pool-fixes
branch
from
September 19, 2026 06:40
63c5b3e to
18fbaca
Compare
Sahil-4555
force-pushed
the
fix/query-relay-pool-fixes
branch
from
September 19, 2026 06:41
18fbaca to
1db81d8
Compare
Sahil-4555
force-pushed
the
fix/query-relay-pool-fixes
branch
from
September 19, 2026 06:49
1db81d8 to
de6ae08
Compare
Contributor
Author
|
Heya @sukunrt @Lide @MarcoPolo l can you please review when get chance? |
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.
Problem
relayFinder.background()startscleanupDisconnectedPeerswith a barego, unlike every other goroutine it spawns, which all go throughrf.refCount.Stop()cancels the context and then waits onrf.refCount, so it can return whilecleanupDisconnectedPeersis still running. Two concrete consequences:Stop()callsresetMetrics()afterrefCount.Wait()returns. The surviving goroutine can callmetricsTracer.ReservationEnded(1)afterwards, leaving a non-zero gauge on a stopped relay finder.Start()/Stop()are restartable on the samerelayFinderandrf.relaysis shared across runs, so a goroutine left over from run N candelete(rf.relays, evt.Peer)a reservation that run N+1 just made.Fix
Track it with
rf.refCount.Go, matching its sibling goroutines. This cannot makeStop()hang.cleanupDisconnectedPeersonly blocks onctx.Done()and its subscription channel, and every send it makes -notifyMaybeConnectToRelay,notifyMaybeNeedNewCandidates,notifyRelayReservationUpdated- is a non-blockingselect/default. TherefCount.Addalso happens while the counter is already non-zero (backgrounditself is tracked), so it is the documented-safeWaitGrouppattern already used at lines 170 and 174.Test
TestStopWaitsForCleanupDisconnectedPeerswraps the event bus so the cleanup goroutine's subscriptionClose()blocks on a channel the test controls. That converts the shutdown race into a deterministic assertion: once the goroutine is parked inClose(),Stop()must not have returned.-race.