XE-13295 · Bounty
[net/sync.go] M9: SyncTo() tidak rate-limit — sync berulang bisa menyebabkan network congestion
Report
Ringkasan
SyncTo dipanggil dari SyncAll (periodik) dan peerSyncWorker (background). Tidak ada rate-limit antara sync attempt. Kalau sync sering gagal, bisa menyebabkan network congestion.
Lokasi
- File:
net/sync.go - Lines: 124-143, 383-404
Kode
func (t *tracker) SyncTo(ctx context.Context, h host.Host, pid peer.ID, opts ...SyncOption) error {
...
if err := t.syncPeer(ctx, h, pid, opts...); err != nil {
return err
}
return nil
}
func (t *tracker) peerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {
...
for {
select {
case <-ctx.Done():
return
case <-t.syncCh[pid]:
if err := t.SyncTo(ctx, h, pid); err != nil {
logging.Warnf("sync: failed to sync with %s: %v", pid, err)
}
}
}
}
Impact
Sync berulang tanpa jeda bisa menyebabkan network congestion, waste bandwidth.
Suggested Fix
func (t *tracker) peerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {
...
for {
select {
case <-ctx.Done():
return
case <-t.syncCh[pid]:
if err := t.SyncTo(ctx, h, pid); err != nil {
logging.Warnf("sync: failed to sync with %s: %v", pid, err)
}
time.Sleep(t.syncInterval) // tambah jeda
}
}
}
Atau gunakan rate limiter per peer:
type rateLimiter struct {
mu sync.Mutex
last map[peer.ID]time.Time
limit time.Duration
}
func (rl *rateLimiter) allow(pid peer.ID) bool {
rl.mu.Lock()
defer rl.mu.Unlock()
now := time.Now()
if t, ok := rl.last[pid]; ok && now.Sub(t) < rl.limit {
return false
}
rl.last[pid] = now
return true
}
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-13295 and says what; it is read like any other.