fix: prune empty topic entries from topics map#543
Open
lodekeeper wants to merge 2 commits intoChainSafe:masterfrom
Open
fix: prune empty topic entries from topics map#543lodekeeper wants to merge 2 commits intoChainSafe:masterfrom
lodekeeper wants to merge 2 commits intoChainSafe:masterfrom
Conversation
Member
|
@lodekeeper please open this PR against the js-libp2p monorepo. This repo will soon be archived |
Author
|
Reopened this against the js-libp2p monorepo here:\n\n- libp2p/js-libp2p#3405\n\nThis is the same empty-topic pruning fix from this PR, ported under |
nflaig
pushed a commit
to ChainSafe/lodestar
that referenced
this pull request
Mar 13, 2026
## Summary Open the Lodestar side of the memory-leak mitigation by clearing composed response-timeout signals in req/resp request handling. This is the Lodestar-local follow-up for the network-thread leak investigation in #8969. It addresses the req/resp timeout-signal retention path by replacing the `AbortSignal.any(...)` composition with a clearable composed signal and explicitly clearing listeners once the response stream is done. This PR is intentionally scoped to the req/resp fix only. The separate residual gossipsub topic-retention issue is being tracked upstream in `ChainSafe/js-libp2p-gossipsub#543`, and we can pick that up once a new libp2p release lands. ## Change - add `createRespSignal()` helper in `packages/reqresp/src/request/index.ts` - compose request signal + timeout signal via an `AbortController` - remove abort listeners explicitly via `respSignal.clear()` after the response closes ## Validation - `pnpm build` - `pnpm lint` *(warning-only: pre-existing unused biome suppression in `packages/light-client/test/unit/webEsmBundle.browser.test.ts`)* ## AI disclosure This PR was authored with AI assistance (Lodekeeper 🌟). --------- Co-authored-by: lodekeeper <lodekeeper@users.noreply.github.com>
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
Fix a
topicsmap retention bug in gossipsub.When a remote peer unsubscribed from a topic, or disconnected after being the last subscriber for a topic, the internal
topics: Map<TopicStr, Set<PeerIdStr>>entry was left behind as an emptySet. Over time this let topic strings accumulate indefinitely.This patch:
topicsentries on remote unsubscribetopicsentries on peer disconnecttopicsentries from unsubscribe-only updatesCloses #542.
Details
The minimal fix is intentionally scoped to
topicsonly.I did not prune
meshentries in the same change becausemeshis local joined-topic state and deleting empty mesh topics on disconnect would interfere with heartbeat maintenance/regrafting.fanoutalready has TTL cleanup, andbackoffalready self-prunes empty per-topic maps.Testing
pnpm test -- --target node --grep 'topic entries|unsubscribe-only'pnpm lintAI disclosure
Initial heap analysis and patch drafting were assisted by AI tooling, then validated with local source inspection and test runs.