Skip to content

Stream leak in SendMsgs — libp2p stream never closed #2

@MastaP

Description

@MastaP

Summary

network/libp2p_network.go:105-136SendMsgs opens a libp2p stream but never closes it. In contrast, sendMsg (line 166-186) properly calls defer s.Close(). Each call to SendMsgs leaks a stream, accumulating file descriptors and memory.

Severity

High — over time this exhausts connection resources, leading to inability to open new streams.

Suggested Fix

Add defer stream.Close() after the stream is opened, matching the pattern in sendMsg.

Related

  • SendMsgs also silently swallows serialization errors: when the for loop completes normally, the function returns nil at line 135, discarding any errors accumulated in resErr (line 125). The return should be resErr instead of nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions