try catch for l2 and no ping/pong
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
|||||||
addOracletoResponse,
|
addOracletoResponse,
|
||||||
l2WithBNToStrings,
|
l2WithBNToStrings,
|
||||||
} from '../utils/utils';
|
} from '../utils/utils';
|
||||||
|
import { logger } from '../utils/logger';
|
||||||
|
|
||||||
type wsMarketL2Args = {
|
type wsMarketL2Args = {
|
||||||
marketIndex: number;
|
marketIndex: number;
|
||||||
@@ -87,7 +88,12 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
override async updateDLOB(): Promise<void> {
|
override async updateDLOB(): Promise<void> {
|
||||||
await super.updateDLOB();
|
await super.updateDLOB();
|
||||||
for (const l2Args of this.marketL2Args) {
|
for (const l2Args of this.marketL2Args) {
|
||||||
|
try {
|
||||||
this.getL2AndSendMsg(l2Args);
|
this.getL2AndSendMsg(l2Args);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
console.log(`Error getting L2 ${l2Args.marketName}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// Handle disconnection
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
// Clear any existing intervals and timeouts
|
// Clear any existing intervals and timeouts
|
||||||
clearInterval(pingIntervalId);
|
|
||||||
clearTimeout(pongTimeoutId);
|
|
||||||
channelSubscribers.forEach((subscribers, channel) => {
|
channelSubscribers.forEach((subscribers, channel) => {
|
||||||
if (subscribers.delete(ws) && subscribers.size === 0) {
|
if (subscribers.delete(ws) && subscribers.size === 0) {
|
||||||
redisClient.client.unsubscribe(channel);
|
redisClient.client.unsubscribe(channel);
|
||||||
|
|||||||
Reference in New Issue
Block a user