<!-- XE-13303 · [net/gossip.go] H2: sendToPeer() tidak handle error — goroutine leak · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13303>. The page is the record; this is the same page for reading.*

XE-13303 · Bounty

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

Closed · invalid
—
[xe#448](https://github.com/xeprotocol/xe/issues/448)
filed 2026-11-12 02:53 UTC
by wahyu20260100233-ops

Verdict
:   Invalid

Tier
:   —

Claimed
:   —

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:51 UTC

Told
:   2026-11-20 00:49 UTC

### Patches

None linked.

### History

- [557390](https://bounty.xe.network/log/557390) 2026-11-20 00:49 UTC reply.mirrored
- [557076](https://bounty.xe.network/log/557076) 2026-11-20 00:48 UTC reply.sent
- [554479](https://bounty.xe.network/log/554479) 2026-11-20 00:37 UTC github.state\_pushed
- [554393](https://bounty.xe.network/log/554393) 2026-11-20 00:37 UTC github.labels
- [553348](https://bounty.xe.network/log/553348) 2026-11-20 00:33 UTC proposal.adopted
- [553149](https://bounty.xe.network/log/553149) 2026-11-20 00:33 UTC proposal.adopted
- [553148](https://bounty.xe.network/log/553148) 2026-11-20 00:33 UTC ticket.status new → closed
- [552687](https://bounty.xe.network/log/552687) 2026-11-20 00:33 UTC proposal.adopted
- [552686](https://bounty.xe.network/log/552686) 2026-11-20 00:33 UTC ticket.facts area
- [552682](https://bounty.xe.network/log/552682) 2026-11-20 00:33 UTC proposal.adopted
- [552681](https://bounty.xe.network/log/552681) 2026-11-20 00:33 UTC ticket.facts
- [550883](https://bounty.xe.network/log/550883) 2026-11-20 00:31 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-13303) · [JSON](https://bounty.xe.network/v1/tickets/XE-13303) · [markdown](https://bounty.xe.network/XE-13303.md)

### 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 desk**team2026-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.
