XE-13292 · Bounty
[net/sync.go] M6: syncIncapable map tidak pernah dibersihkan — memory leak kecil
Report
Ringkasan
syncIncapable di-set di markSyncIncapable() tapi hanya di-clean di removePeer() (yang dipanggil dari DisconnectedF). Kalau peer tidak pernah disconnect, entry tetap ada selamanya. Tidak ada cleanup berdasarkan waktu.
Lokasi
- File:
net/sync.go - Lines: 78, 153-163
Kode
func (t *tracker) markSyncIncapable(pid peer.ID) {
t.mu.Lock()
t.syncIncapable[pid] = struct{}{}
t.mu.Unlock()
}
func (t *tracker) removePeer(pid peer.ID) {
t.mu.Lock()
delete(t.syncIncapable, pid)
t.mu.Unlock()
}
Impact
Memory leak kecil (map tumbuh). Kalau ada banyak peer yang connect dan disconnect tidak pernah terjadi, map tumbuh tanpa batas.
Suggested Fix
func (t *tracker) markSyncIncapable(pid peer.ID) {
t.mu.Lock()
t.syncIncapable[pid] = time.Now() // simpan timestamp
t.mu.Unlock()
}
func (t *tracker) removePeer(pid peer.ID) {
t.mu.Lock()
delete(t.syncIncapable, pid)
t.mu.Unlock()
}
// tambah cleanup periodic
func (t *tracker) cleanupSyncIncapable() {
t.mu.Lock()
now := time.Now()
for pid, t := range t.syncIncapable {
if now.Sub(t) > 24*time.Hour {
delete(t.syncIncapable, pid)
}
}
t.mu.Unlock()
}
Atau gunakan TTL-based map.
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-13292 and says what; it is read like any other.