From 27bfef5a1ef0b8e2cfd83cc168365b0e892ff58b Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Mon, 11 Dec 2023 06:51:41 -0800 Subject: [PATCH] try catch for l2 and no ping/pong --- src/dlob-subscriber/DLOBSubscriberIO.ts | 8 +++++++- src/wsConnectionManager.ts | 22 ---------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 0a20194..1f6faf1 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -18,6 +18,7 @@ import { addOracletoResponse, l2WithBNToStrings, } from '../utils/utils'; +import { logger } from '../utils/logger'; type wsMarketL2Args = { marketIndex: number; @@ -87,7 +88,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber { override async updateDLOB(): Promise { await super.updateDLOB(); for (const l2Args of this.marketL2Args) { - this.getL2AndSendMsg(l2Args); + try { + this.getL2AndSendMsg(l2Args); + } catch (error) { + logger.error(error); + console.log(`Error getting L2 ${l2Args.marketName}`); + } } } diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index 744b6fd..bb37b5c 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -233,31 +233,9 @@ async function main() { } }); - // Ping/pong connection timeout - let pongTimeoutId; - let isAlive = true; - const pingIntervalId = setInterval(() => { - isAlive = false; - pongTimeoutId = setTimeout(() => { - if (!isAlive) { - console.log('Disconnecting because of ping/pong timeout'); - ws.terminate(); - } - }, 5000); // 5 seconds to wait for a pong - ws.ping(); - }, 30000); - - // Listen for pong messages - ws.on('pong', () => { - isAlive = true; - clearTimeout(pongTimeoutId); - }); - // Handle disconnection ws.on('close', () => { // Clear any existing intervals and timeouts - clearInterval(pingIntervalId); - clearTimeout(pongTimeoutId); channelSubscribers.forEach((subscribers, channel) => { if (subscribers.delete(ws) && subscribers.size === 0) { redisClient.client.unsubscribe(channel);