Guard PresenceManager.Start against duplicate sweep goroutines#808
Open
AbirAbbas wants to merge 1 commit into
Open
Guard PresenceManager.Start against duplicate sweep goroutines#808AbirAbbas wants to merge 1 commit into
AbirAbbas wants to merge 1 commit into
Conversation
…cate sweep goroutines Start() now uses sync.Once (mirroring the existing stopOnce pattern) to ensure only one sweep loop is ever spawned per PresenceManager instance. Adds two regression tests: - TestPresenceManager_Start_Idempotent: counts goroutines before/after multiple Start() calls to assert no duplicate sweep loops spawn. - TestPresenceManager_ExpireCallback_OncePerExpiration: counts callback invocations across multiple sweep cycles to assert the callback fires at most once per expired node lease. Verification: temporarily reverted the startOnce guard and confirmed TestPresenceManager_Start_Idempotent fails with delta=3 (3 extra goroutines spawned by duplicate Start() calls), proving the regression test catches the bug. Restored the guard; all presence manager tests pass and go vet is clean.
AbirAbbas
marked this pull request as draft
July 21, 2026 22:12
Contributor
📊 Coverage gateThresholds from
✅ Gate passedNo surface regressed past the allowed threshold and the aggregate stayed above the floor. |
Contributor
📐 Patch coverage gateThreshold: 80% on lines this PR touches vs
✅ Patch gate passedEvery surface whose lines were touched by this PR has patch coverage at or above the threshold. |
AbirAbbas
marked this pull request as ready for review
July 22, 2026 13:41
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.
Summary
PresenceManager.Startwithsync.Once, mirroring the existingstopOncepattern so only one sweep loop is ever spawned per instance.Changes
control-plane/internal/services/presence_manager.go— addedstartOnce sync.Oncefield and wrappedStart()body so duplicate calls are no-ops.control-plane/internal/services/presence_manager_test.go— addedTestPresenceManager_Start_Idempotent(asserts no extra goroutines across repeatedStart()calls) andTestPresenceManager_ExpireCallback_OncePerExpiration(asserts the expire callback fires at most once per expired lease across multiple sweep cycles).Test plan
go vet ./...is clean.TestPresenceManager*tests pass.control-plane/internal/servicessuite passes under-racewith-gcflags=all=-d=checkptr=0(pre-existing boltdb v1.3.1 checkptr incompatibility with Go 1.25 race detector exists on main and is unrelated to this change).startOnceguard and confirmedTestPresenceManager_Start_Idempotentfails withdelta=3(3 extra goroutines from duplicateStart()calls), proving the regression test catches the bug; restored the guard.🤖 Built with AgentField SWE-AF
🔌 Powered by AgentField