Bounty
XE-13286 · Bounty

[net/netcheck.go] L15: handleNetcheckInbound() tidak handle concurrent requests — potensi race

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

Report

Ringkasan

Stream handler di-register tanpa mutex protection. Kalau multiple stream datang bersamaan, handler dijalankan secara concurrent. Tidak ada issue yang ditemukan, tapi worth noting.

Lokasi

  • File: net/netcheck.go
  • Lines: 391-416

Kode

func (g *NetworkGater) SetupNetcheckHandler(h host.Host, gater *NetworkGater) {
    h.SetStreamHandler(NetcheckProtocolID, func(s network.Stream) {
        defer func() { _ = s.Close() }()
        g.handleNetcheckInbound(s)
    })
}

func (g *NetworkGater) handleNetcheckInbound(s network.Stream) {
    ...
    // handler dijalankan tanpa mutex protection
}

Impact

Kalau multiple stream datang bersamaan, handler dijalankan secara concurrent. Meskipun saat ini tidak ada issue yang ditemukan, handler harus thread-safe.

Suggested Fix

Document bahwa handler harus thread-safe, atau tambah mutex protection:

func (g *NetworkGater) handleNetcheckInbound(s network.Stream) {
    g.mu.Lock()
    defer g.mu.Unlock()
    ...
}

Atau lebih baik: gunakan goroutine per stream dan jangan pakai shared state tanpa synchronization.

func (g *NetworkGater) SetupNetcheckHandler(h host.Host, gater *NetworkGater) {
    h.SetStreamHandler(NetcheckProtocolID, func(s network.Stream) {
        defer func() { _ = s.Close() }()
        go g.handleNetcheckInbound(s)  // setiap stream di-handle di goroutine terpisah
    })
}

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