fix(service-discovery): drain bootstrap futures on shutdown#2823
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix issue with open streams after auto-advertise test
fix(service-discovery): drain bootstrap futures on shutdown
Jul 13, 2026
vladopajic
approved these changes
Jul 13, 2026
vladopajic
marked this pull request as ready for review
July 13, 2026 19:22
vladopajic
enabled auto-merge
July 13, 2026 19:22
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2823 +/- ##
==========================================
- Coverage 81.07% 81.06% -0.02%
==========================================
Files 171 171
Lines 31135 31134 -1
Branches 12 13 +1
==========================================
- Hits 25244 25239 -5
- Misses 5891 5895 +4
🚀 New features to boost your workflow:
|
richard-ramos
approved these changes
Jul 13, 2026
|
|
||
| disco.serviceBootstrapFuts.cancelSoon() | ||
| disco.serviceBootstrapFuts = @[] | ||
| let serviceBootstrapFuts = move disco.serviceBootstrapFuts |
gmelodie
approved these changes
Jul 14, 2026
| # stops the advertiser maintenance loop before draining advertiser tasks, | ||
| # so shutdown cannot spawn new registration work while cleanup is running | ||
| if not disco.advertiserMaintenanceLoop.isNil(): | ||
| if not disco.advertiserMaintenanceLoop.isNil: |
Contributor
There was a problem hiding this comment.
nit?
Suggested change
| if not disco.advertiserMaintenanceLoop.isNil: | |
| if not disco.advertiserMaintenanceLoop.isNil(): |
Member
There was a problem hiding this comment.
adjective-like getters should not use ()
gmelodie
pushed a commit
that referenced
this pull request
Jul 14, 2026
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Vlado Pajić <vlado@brrrrr.at>
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
auto-advertise on startcould leave a service-discovery RPC stream alive after teardown because bootstrap futures were only signaled for cancellation, not drained. This change makes shutdown wait for those bootstrap cancellations to complete so the associated streams close before tracker checks run.Root cause
ServiceDiscovery.stop()clearedserviceBootstrapFutsaftercancelSoon()LPChannelcould remain open long enough to poison later testsChange
raises: []shutdown contract by waiting throughnoCancelcancelAndWaitto have same pattern in this procAffected Areas
Gossipsub
Transports
Peer Management / Discovery
Protocol Logic
Build / Tooling
Other
Compatibility & Downstream Validation
Reference PRs / branches / commits demonstrating successful integration:
Nimbus:
N/A
Waku:
N/A
Codex:
N/A
Impact on Library Users
No API change. Internal shutdown behavior is stricter: service-discovery now waits for bootstrap work to finish cancelling before completing stop, which removes a teardown race without changing steady-state protocol behavior.
Risk Assessment
Low risk.
References
bug: auto-advertise on startvacp2p/nim-libp2p#2822Additional Notes
This is intentionally narrow in scope: only bootstrap future teardown changed. Other service-discovery background loops keep their existing shutdown behavior.