Skip to content

Fix leak around different lifecycles of inbound vs outbound streams. - #691

Merged
MarcoPolo merged 2 commits into
masterfrom
marco/fix-leak-incoming-stream
Apr 17, 2026
Merged

MarcoPolo merged 2 commits into
masterfrom
marco/fix-leak-incoming-stream

Conversation

@MarcoPolo

Copy link
Copy Markdown
Contributor

In certain cases peer state may be leaked if the state is created on incoming messages and only cleared when our outbound stream is closed.

@MarcoPolo
MarcoPolo requested a review from sukunrt April 10, 2026 21:40
Comment thread pubsub.go
for t, tmap := range p.topics {
if _, ok := tmap[pid]; ok {
delete(tmap, pid)
p.notifyLeave(t, pid)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe these four statements should be a method.

q.Close()
delete(p.peers, pid)
p.clearPeerFromTopicsState(pid)
p.rt.RemovePeer(pid)

Comment thread pubsub.go
in.s.Conn().RemotePeer(), in.s.Protocol())
case incomingKindClosedStream:
p.onClosedIncomingStream(
in.s.Conn().RemotePeer(), in.s.Protocol())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the protocol in onClosedIncomingStream? in.s.Protocol()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice symmetry, and lets you cleanup state associated with a specific gossipsub version. For example, if extensions is supported you need to clean up extensions state.

Of course you could just always clean up all state, but this seems a little clearer.

In certain cases peer state may be leaked if the state is created on
incoming messages and only cleared when our outbound stream is closed.
@MarcoPolo
MarcoPolo force-pushed the marco/fix-leak-incoming-stream branch from 75e8d29 to d8037f3 Compare April 17, 2026 20:28
@MarcoPolo
MarcoPolo merged commit d8037f3 into master Apr 17, 2026
9 checks passed
@MarcoPolo
MarcoPolo deleted the marco/fix-leak-incoming-stream branch April 17, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants