XE-13299 · Bounty
[net/sync.go] M13: syncPeer() tidak handle context cancellation di tengah sync — resource leak
Report
Ringkasan
Kalau context cancelled di tengah doFullSync, goroutine tetap jalan sampai selesai. Tidak ada cleanup mechanism.
Lokasi
- File:
net/sync.go - Lines: 248-274, 315-331
Kode
func (t *tracker) syncPeer(ctx context.Context, h host.Host, pid peer.ID, opts ...SyncOption) error {
...
if err := t.doFullSync(ctx, h, pid, opts...); err != nil {
return err
}
return nil
}
func (t *tracker) doFullSync(ctx context.Context, h host.Host, pid peer.ID, opts ...SyncOption) error {
...
// context cancellation tidak di-handle di tengah sync
if err := t.syncData(ctx, h, pid, opts...); err != nil {
return err
}
...
}
Impact
Resource leak kalau context cancelled. Goroutine tetap jalan.
Suggested Fix
func (t *tracker) syncPeer(ctx context.Context, h host.Host, pid peer.ID, opts ...SyncOption) error {
...
done := make(chan error, 1)
go func() {
done <- t.doFullSync(ctx, h, pid, opts...)
}()
select {
case err := <-done:
return err
case <-ctx.Done():
// cleanup jika perlu
return ctx.Err()
}
}
Atau implement cancel mechanism di dalam doFullSync:
func (t *tracker) doFullSync(ctx context.Context, h host.Host, pid peer.ID, opts ...SyncOption) error {
...
if err := t.syncData(ctx, h, pid, opts...); err != nil {
if ctx.Err() != nil {
// cleanup jika context cancelled
t.cancelSync(pid)
}
return err
}
...
}
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-13299 and says what; it is read like any other.