Bounty
XE-13276 · Bounty

[net/msg.go] L5: MaxConcurrent=50 tanpa backpressure — resource exhaustion kalau handler lambat

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

Report

Ringkasan

MaxConcurrent = 50 tapi tidak ada backpressure mechanism kalau handler lambat. Request bisa menumpuk di queue dan menyebabkan memory growth.

Lokasi

  • File: net/msg.go
  • Lines: 27-28, 157-163

Kode

const (
    requestTimeout = 15 * time.Second
    maxConcurrent  = 50
)

func (m *Messenger) Start(h host.Host, ng *NetworkGater, opts ...Option) {
    ...
    m.inflight = make(chan struct{}, maxConcurrent)
    m.requests = make(chan msgRequest, 1000)  // queue tanpa batas
    ...
}

Impact

Queue requests bisa tumbuh tanpa batas kalau handler lambat. Memory growth, potensi OOM.

Suggested Fix

func (m *Messenger) Start(h host.Host, ng *NetworkGater, opts ...Option) {
    ...
    m.inflight = make(chan struct{}, maxConcurrent)
    m.requests = make(chan msgRequest, 1000)
    m.maxQueueSize = 5000  // tambah config
    ...
}

func (m *Messenger) request(pid peer.ID, msgType string, payload interface{}, timeout time.Duration) (json.RawMessage, error) {
    ...
    select {
    case m.requests <- req:
    case <-time.After(100 * time.Millisecond):
        return nil, ErrQueueFull
    }
    ...
}

Atau gunakan backpressure: kalau queue penuh, reject request dengan error.

m.requests = make(chan msgRequest, 1000)
// di request():
select {
case m.requests <- req:
case <-time.After(100 * time.Millisecond):
    return nil, ErrQueueFull
}

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