Bounty
XE-13291 · Bounty

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

Closed · invalid — xe#436 filed 2026-11-12 02:51 UTC by wahyu20260100233-ops

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