possible memory leak fixes

This commit is contained in:
Nour Alharithi
2023-12-11 18:52:46 -08:00
parent 54d463f84e
commit c1a5afe3d7
3 changed files with 6 additions and 3 deletions

View File

@@ -99,7 +99,10 @@ async function main() {
const subscribers = channelSubscribers.get(subscribedChannel);
if (subscribers) {
subscribers.forEach((ws) => {
ws.send(JSON.stringify({ channel: subscribedChannel, data: message }));
if (ws.readyState === WebSocket.OPEN)
ws.send(
JSON.stringify({ channel: subscribedChannel, data: message })
);
});
}
});
@@ -110,7 +113,6 @@ async function main() {
wss.on('connection', (ws: WebSocket) => {
console.log('Client connected');
console.log('Number of active connections:', wss.clients.size);
wsConnectionsGauge.inc();
ws.on('message', async (msg) => {
@@ -245,7 +247,6 @@ async function main() {
subscribedChannels.delete(channel);
}
});
console.log('Number of active connections:', wss.clients.size);
wsConnectionsGauge.dec();
});