<!-- XE-0752 · SSE subscribers unbounded — every chat broadcast walks all listeners under one lock · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0752>. The page is the record; this is the same page for reading.*

XE-0752 · Bounty

# SSE subscribers unbounded — every chat broadcast walks all listeners under one lock

Closed · duplicate
—
[xe#280](https://github.com/xeprotocol/xe/issues/280)
filed 2026-11-05 15:53 UTC
by adli582

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   —

Duplicate of
:   [XE-0027](https://bounty.xe.network/XE-0027) accepted

Tracked
:   —

Updated
:   2026-11-10 00:11 UTC

Told
:   2026-11-06 08:14 UTC

### Patches

None linked.

### History

- [12033](https://bounty.xe.network/log/12033) 2026-11-06 08:15 UTC github.state\_pushed
- [12032](https://bounty.xe.network/log/12032) 2026-11-06 08:14 UTC github.labels
- [12008](https://bounty.xe.network/log/12008) 2026-11-06 08:14 UTC reply.mirrored
- [12004](https://bounty.xe.network/log/12004) 2026-11-06 08:14 UTC reply.sent
- [12003](https://bounty.xe.network/log/12003) 2026-11-06 08:14 UTC proposal.adopted
- [12002](https://bounty.xe.network/log/12002) 2026-11-06 08:14 UTC ticket.status new → closed
- [12001](https://bounty.xe.network/log/12001) 2026-11-06 08:14 UTC proposal.adopted
- [12000](https://bounty.xe.network/log/12000) 2026-11-06 08:14 UTC ticket.facts
- [11999](https://bounty.xe.network/log/11999) 2026-11-06 08:14 UTC proposal.adopted
- [11998](https://bounty.xe.network/log/11998) 2026-11-06 08:14 UTC ticket.facts
- [11828](https://bounty.xe.network/log/11828) 2026-11-06 07:47 UTC proposal.created
- [11827](https://bounty.xe.network/log/11827) 2026-11-06 07:47 UTC proposal.created

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

### Report

//#What happens

`GET /chat/events` (api/chat.go:78) calls `SubscribeChat()` once per connected client. In `chat/chat.go`:

go
func (s ChatStore) Subscribe() (chan Envelope, func()) {
ch :\= make(chan \*Envelope, 64\)
s.listenerMu.Lock()
s.listeners \= append(s.listeners, ch) // \<- no cap, no per-IP limit, nothing
s.listenerMu.Unlock()
...
}

There is no cap on `listeners`. And every `Store()` does this:

go
s.listenerMu.Lock()
for \_, ch :\= range s.listeners {
select {
case ch \<- env:
default:
}
}
s.listenerMu.Unlock()

So the cost of delivering one chat message is O(number of SSE connections on the node), all while holding `listenerMu` — which every `Store()` (i.e. every incoming p2p `account_chat` and every `POST /chat/send`) also needs.

Auth for `/chat/events` is a one-time challenge\+signature. The read rate limit is 200 req/s sustained, burst 1000 per IP. So one machine can stack up 200 connections per second, each one a permanent listener \+ goroutine.

## Measured impact

I benchmarked the real `ChatStore` with N subscribers and timed `Store()`:
listeners\=0 Store() avg\=45ns heap\=0.6 MB
listeners\=1000 Store() avg\=689ns heap\=1.3 MB
listeners\=10000 Store() avg\=5.5µs heap\=7.5 MB
listeners\=50000 Store() avg\=77.7µs heap\=36.5 MB

50k connections (reachable in \~4 min from a single IP at the allowed rate) makes every chat broadcast \~1700x slower and serializes all chat ingestion behind `listenerMu`. Chat delivery for legitimate users degrades linearly while the attacker holds the connections open — and it costs the attacker nothing per message after connect.

## Repro

go
store :\= chat.NewChatStore(100)
subs :\= make(\[\]func(), 0, N)
for i :\= 0; i \< N; i\+\+ {
\_, unsub :\= store.Subscribe()
subs \= append(subs, unsub)
}
// now time store.Store(env) — grows linearly with N, see numbers above

End-to-end version: open N `GET /chat/events?account=...&challenge=...&sig=...&pub_key=...` connections, keep them idle (the 20s ping keeps them alive), then watch `/chat/send` latency climb.

## Related oddity

`http.Server` is created with `WriteTimeout: 60s` (cmd/xe/main.go:1458) but SSE connections need to live indefinitely — either the write deadline kills every SSE stream at 60s (making the feature broken for real users) or it's exempted somehow. Might be worth checking while fixing this.

## Suggested fix

Cap total listeners (e.g. 256\) and reject new SSE connections beyond that; or per-IP SSE connection limit; and/or move broadcast outside the store lock (snapshot the slice, release, then fan out).

This lands under the Track 2 bullet "Chat, SSE and API starvation under many concurrent clients" almost word for word.

### Thread

**Joseph Denne**team2026-11-06 08:14 UTCgithub

Thanks. This is the same finding as https://bounty.xe.network/XE-0027, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, reply with what differs and we will look again.
