<!-- XE-13291 · [net/sync.go] M5: MarkDirty() tidak pakai mutex — logical race dengan clearDirty() · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13291>. The page is the record; this is the same page for reading.*

XE-13291 · Bounty

# \[net/sync.go\] M5: MarkDirty() tidak pakai mutex — logical race dengan clearDirty()

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

- [557785](https://bounty.xe.network/log/557785) 2026-11-20 00:49 UTC reply.mirrored
- [557089](https://bounty.xe.network/log/557089) 2026-11-20 00:48 UTC reply.sent
- [554946](https://bounty.xe.network/log/554946) 2026-11-20 00:37 UTC github.state\_pushed
- [554937](https://bounty.xe.network/log/554937) 2026-11-20 00:37 UTC github.labels
- [553361](https://bounty.xe.network/log/553361) 2026-11-20 00:33 UTC proposal.adopted
- [553174](https://bounty.xe.network/log/553174) 2026-11-20 00:33 UTC proposal.adopted
- [553173](https://bounty.xe.network/log/553173) 2026-11-20 00:33 UTC ticket.status new → closed
- [552813](https://bounty.xe.network/log/552813) 2026-11-20 00:33 UTC proposal.adopted
- [552812](https://bounty.xe.network/log/552812) 2026-11-20 00:33 UTC ticket.facts area
- [552807](https://bounty.xe.network/log/552807) 2026-11-20 00:33 UTC proposal.adopted
- [552806](https://bounty.xe.network/log/552806) 2026-11-20 00:33 UTC ticket.facts
- [550772](https://bounty.xe.network/log/550772) 2026-11-20 00:30 UTC note.added

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

### Report

## Ringkasan

`syncTracker.dirty` diakses dengan dua mekanisme yang tidak sinkron:

- `MarkDirty()` pakai `sync2.StoreInt32(&st.dirty, 1)` (atomic, tanpa mutex)
- `clearDirty()` pakai `sync2.StoreInt32(&st.dirty, 0)` (atomic, tapi dipanggil setelah release mutex)
- `shouldSync()` baca `sync2.LoadInt32(&st.dirty)` di dalam mutex

Race condition: `clearDirty` me-release mutex lalu baru set `dirty=0`. Di jendela antara release mutex dan `StoreInt32`, `MarkDirty` bisa set `dirty=1`. Hasilnya: `shouldSync` return `true` meskipun full resync baru saja terjadi — node melakukan sync yang tidak perlu.

## Lokasi

- File: `net/sync.go`
- Lines: 73-74, 93-98, 138-143, 394

## Kode

```
func (st *syncTracker) MarkDirty() {
    sync2.StoreInt32(&st.dirty, 1)
}

func (st *syncTracker) clearDirty() {
    st.mu.Lock()
    st.lastFullResync = time.Now()
    st.mu.Unlock()
    sync2.StoreInt32(&st.dirty, 0)  // di luar mutex
}
```

## Impact

Sync berlebihan, waste bandwidth, potensi infinite sync loop kalau `MarkDirty` terus dipanggil.

## Suggested Fix

```
func (st *syncTracker) clearDirty() {
    st.mu.Lock()
    st.lastFullResync = time.Now()
    sync2.StoreInt32(&st.dirty, 0)  // pindahkan ke dalam mutex
    st.mu.Unlock()
}
```

Atau gunakan atomic operation yang konsisten:

```
func (st *syncTracker) MarkDirty() {
    st.mu.Lock()
    sync2.StoreInt32(&st.dirty, 1)
    st.mu.Unlock()
}
```

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