Set a max subscriptions size per connection

This commit is contained in:
Alex Gleason 2025-03-16 17:51:07 -05:00
parent a6b58b50cf
commit f27609feb8
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -153,6 +153,11 @@ function connectStream(socket: WebSocket, ip: string | undefined, opts: ConnectS
async function handleReq([_, subId, ...filters]: NostrClientREQ): Promise<void> {
if (rateLimited(limiters.req)) return;
if (controllers.size > 20) {
send(['CLOSED', subId, 'error: too many subscriptions']);
return;
}
const controller = new AbortController();
controllers.get(subId)?.abort();
controllers.set(subId, controller);