mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
streaming: ensure close handler is called even when socket is closed by server
This commit is contained in:
parent
f27609feb8
commit
497b02002e
1 changed files with 12 additions and 3 deletions
|
|
@ -179,22 +179,31 @@ const streamingController: AppController = async (c) => {
|
|||
limiter.set(ip, count + 1, { ttl: LIMITER_WINDOW });
|
||||
|
||||
if (count > LIMITER_LIMIT) {
|
||||
socket.close(1008, 'Rate limit exceeded');
|
||||
closeSocket(1008, 'Rate limit exceeded');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof e.data !== 'string') {
|
||||
socket.close(1003, 'Invalid message');
|
||||
closeSocket(1003, 'Invalid message');
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
socket.onclose = () => {
|
||||
handleClose();
|
||||
};
|
||||
|
||||
function closeSocket(code?: number, reason?: string) {
|
||||
socket.close(code, reason);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
function handleClose(): void {
|
||||
connections.delete(socket);
|
||||
streamingConnectionsGauge.set(connections.size);
|
||||
controller.abort();
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue