Merge pull request #48 from drift-labs/master

possible memory leak fixes
This commit is contained in:
Nour Alharithi
2023-12-11 18:58:39 -08:00
committed by GitHub
2 changed files with 5 additions and 3 deletions

View File

@@ -56,6 +56,7 @@
"dlob-publish": "ts-node src/publishers/dlobPublisher.ts", "dlob-publish": "ts-node src/publishers/dlobPublisher.ts",
"trades-publish": "ts-node src/publishers/tradesPublisher.ts", "trades-publish": "ts-node src/publishers/tradesPublisher.ts",
"ws-manager": "ts-node src/wsConnectionManager.ts", "ws-manager": "ts-node src/wsConnectionManager.ts",
"ws-manager:inspect": "yarn build && node --inspect ./lib/wsConnectionManager.js",
"dev:inspect": "yarn build && node --inspect ./lib/index.js", "dev:inspect": "yarn build && node --inspect ./lib/index.js",
"dev:debug": "yarn build && node --inspect-brk --inspect=2230 ./lib/index.js", "dev:debug": "yarn build && node --inspect-brk --inspect=2230 ./lib/index.js",
"example": "ts-node example/client.ts", "example": "ts-node example/client.ts",

View File

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