<!-- XE-13299 · [net/sync.go] M13: syncPeer() tidak handle context cancellation di tengah sync — resource leak · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13299>. The page is the record; this is the same page for reading.*

XE-13299 · Bounty

# \[net/sync.go\] M13: syncPeer() tidak handle context cancellation di tengah sync — resource leak

Closed · invalid
—
[xe#444](https://github.com/xeprotocol/xe/issues/444)
filed 2026-11-12 02:52 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

- [557442](https://bounty.xe.network/log/557442) 2026-11-20 00:49 UTC reply.mirrored
- [557081](https://bounty.xe.network/log/557081) 2026-11-20 00:48 UTC reply.sent
- [554549](https://bounty.xe.network/log/554549) 2026-11-20 00:37 UTC github.state\_pushed
- [554533](https://bounty.xe.network/log/554533) 2026-11-20 00:37 UTC github.labels
- [553352](https://bounty.xe.network/log/553352) 2026-11-20 00:33 UTC proposal.adopted
- [553157](https://bounty.xe.network/log/553157) 2026-11-20 00:33 UTC proposal.adopted
- [553156](https://bounty.xe.network/log/553156) 2026-11-20 00:33 UTC ticket.status new → closed
- [552733](https://bounty.xe.network/log/552733) 2026-11-20 00:33 UTC proposal.adopted
- [552732](https://bounty.xe.network/log/552732) 2026-11-20 00:33 UTC ticket.facts area
- [552728](https://bounty.xe.network/log/552728) 2026-11-20 00:33 UTC proposal.adopted
- [552727](https://bounty.xe.network/log/552727) 2026-11-20 00:33 UTC ticket.facts
- [550861](https://bounty.xe.network/log/550861) 2026-11-20 00:31 UTC note.added

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

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