Bounty
XE-13301 · Bounty

[net/sync.go] M15: syncChan tidak di-close saat peer disconnect — goroutine leak

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

Report

Ringkasan

syncCh di-create di startPeerSyncWorker tapi tidak di-close saat peer disconnect. Goroutine yang menunggu di channel tersebut tetap berjalan.

Lokasi

  • File: net/sync.go
  • Lines: 383-404

Kode

func (t *tracker) startPeerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {
    t.mu.Lock()
    t.syncCh[pid] = make(chan struct{}, 1)
    t.mu.Unlock()
    go t.peerSyncWorker(ctx, h, pid)
}

func (t *tracker) peerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {
    ...
    for {
        select {
        case <-ctx.Done():
            return
        case <-t.syncCh[pid]:
            ...
        }
    }
}

Impact

Goroutine leak kalau peer disconnect. Channel tidak di-close.

Suggested Fix

func (t *tracker) stopPeerSyncWorker(pid peer.ID) {
    t.mu.Lock()
    if ch, ok := t.syncCh[pid]; ok {
        close(ch)
        delete(t.syncCh, pid)
    }
    t.mu.Unlock()
}

func (t *tracker) peerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {
    ...
    for {
        select {
        case <-ctx.Done():
            t.stopPeerSyncWorker(pid)
            return
        case <-t.syncCh[pid]:
            ...
        }
    }
}

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-13301 and says what; it is read like any other.