Bounty
XE-13303 · Bounty

[net/gossip.go] H2: sendToPeer() tidak handle error — goroutine leak

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

Report

Ringkasan

Kalau sendToPeer gagal, error hanya di-log. Tidak ada cleanup. Kalau error terjadi berulang, goroutine yang di-spawn bisa menumpuk.

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)
    }
    ...
    if err := stream.Close(); err != nil {
        return fmt.Errorf("gossip: failed to close stream: %w", err)
    }
    return nil
}

Impact

Goroutine leak kalau send gagal berulang. Resource exhaustion.

Suggested Fix

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)
        g.mu.Lock()
        g.failedPeers[pid] = time.Now()
        g.mu.Unlock()
        return
    }
    ...
}

// tambah cleanup periodic
func (g *Gossip) cleanupFailedPeers() {
    g.mu.Lock()
    now := time.Now()
    for pid, t := range g.failedPeers {
        if now.Sub(t) > 5*time.Minute {
            delete(g.failedPeers, pid)
        }
    }
    g.mu.Unlock()
}

Thread

XE deskteam2026-11-20 00:49 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-13303 and says what; it is read like any other.