From ccff8058e59273c8a127bcd62c05e10f7d3be553 Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Thu, 30 Jun 2022 15:08:07 +0300 Subject: [PATCH] OP-2481 Fixup --- src/services/OrionAggregator/ws/index.ts | 5 ++++- src/services/PriceFeed/ws/PriceFeedSubscription.ts | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 4ea7e0b..db8e06b 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -144,6 +144,8 @@ const isSubType = (subType: string): subType is keyof Subscription => Object.val class OrionAggregatorWS { private ws: WebSocket | undefined; + private isClosedIntentionally: boolean = false; + private subscriptions: Partial<{ [K in keyof Subscription]: Partial> }> = {}; @@ -254,6 +256,7 @@ class OrionAggregatorWS { } destroy() { + this.isClosedIntentionally = true; this.ws?.close(); delete this.ws; } @@ -261,7 +264,7 @@ class OrionAggregatorWS { init(isReconnect = false) { this.ws = new WebSocket(this.wsUrl); this.ws.onclose = (e) => { - if (this.ws) this.init(true); + if (!this.isClosedIntentionally) this.init(true); }; this.ws.onopen = () => { // Re-subscribe to all subscriptions diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 513f9f8..36f257b 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -74,6 +74,8 @@ export default class PriceFeedSubscription { if (this.heartbeatInterval) clearInterval(this.heartbeatInterval); - if (this.ws) this.init(); + if (!this.isClosedIntentionally) this.init(); }; this.heartbeatInterval = setInterval(() => { @@ -117,7 +119,7 @@ export default class PriceFeedSubscription