Bounty
XE-13310 · Bounty

[net/gossip.go] H9: sendToPeer() tidak handle context cancellation — goroutine leak

Closed · invalid — xe#455 filed 2026-11-12 02:54 UTC by wahyu20260100233-ops

Report

Ringkasan

Kalau context cancelled, sendToPeer goroutine tetap berjalan sampai selesai. Tidak ada cleanup mechanism.

Lokasi

  • File: net/gossip.go
  • Lines: 189-218

Kode

func (g *Gossip) sendToPeer(pid peer.ID, key string, msg []byte) {
    ...
    if err := g.sendMessage(pid, key, msg); err != nil {
        logging.Warnf("gossip: failed to send message to %s: %v", pid, err)
        return
    }
    ...
}

func (g *Gossip) sendMessage(pid peer.ID, key string, msg []byte) error {
    ...
    if err := g.host.Connect(g.ctx, peer.AddrInfo{ID: pid}); err != nil {
        return fmt.Errorf("gossip: failed to connect to %s: %w", pid, err)
    }
    ...
}

Impact

Goroutine leak kalau context cancelled. Resource exhaustion.

Suggested Fix

func (g *Gossip) sendToPeer(ctx context.Context, pid peer.ID, key string, msg []byte) {
    ...
    select {
    case <-ctx.Done():
        return
    default:
        if err := g.sendMessage(ctx, pid, key, msg); err != nil {
            logging.Warnf("gossip: failed to send message to %s: %v", pid, err)
            return
        }
    }
    ...
}

Thread

XE deskteam2026-11-20 00:50 UTCgithub

Thanks for the report. We read it against the code and could not confirm a bug in what it describes.

This report is closed as invalid. If we have missed something, file a new report that links https://bounty.xe.network/XE-13310 and says what; it is read like any other.