Bounty
XE-13314 · Bounty

[net/gossip.go] H13: gossipHandler() tidak handle concurrent write ke shared state — race condition

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

Report

Ringkasan

Kalau multiple stream handler dijalankan bersamaan dan modify shared state (misalnya g.peers), bisa terjadi race condition.

Lokasi

  • File: net/gossip.go
  • Lines: 219-245

Kode

func (g *Gossip) gossipHandler(stream network.Stream) {
    ...
    var msg GossipMessage
    if err := gob.NewDecoder(stream).Decode(&msg); err != nil {
        logging.Debugf("gossip: failed to decode message: %v", err)
        return
    }
    // handler modify shared state tanpa synchronization
    g.handleMessage(msg)
}

Impact

Race condition kalau multiple handler modify shared state bersamaan.

Suggested Fix

func (g *Gossip) gossipHandler(stream network.Stream) {
    ...
    var msg GossipMessage
    if err := gob.NewDecoder(stream).Decode(&msg); err != nil {
        logging.Debugf("gossip: failed to decode message: %v", err)
        return
    }
    
    // gunakan channel-based approach untuk menghindari race condition
    g.msgChan <- msg
}

func (g *Gossip) messageProcessor() {
    for msg := range g.msgChan {
        g.handleMessage(msg)
    }
}

Thread

XE deskteam2026-11-20 00:50 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-13314 and says what; it is read like any other.