From b7ad04410d0a18daff5cbdf607ec74ad2143bda8 Mon Sep 17 00:00:00 2001 From: Inrixia Date: Sun, 13 Oct 2024 17:48:10 +1300 Subject: [PATCH] Ensure that socket reconnection is not triggered multiple times --- src/lib/prometheus.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/prometheus.ts b/src/lib/prometheus.ts index d08c3b1..643b8ac 100644 --- a/src/lib/prometheus.ts +++ b/src/lib/prometheus.ts @@ -15,12 +15,14 @@ new Gauge({ .set(1); let socket: WebSocket | undefined; +let reconnectTimeout: NodeJS.Timeout; export const initProm = (instance: string) => { if (settings.metrics.contributeMetrics) { const connect = () => { const onError = () => { socket?.terminate(); - setTimeout(connect, 1000); + clearTimeout(reconnectTimeout); + reconnectTimeout = setTimeout(connect, 1000); }; socket?.terminate(); socket = new WebSocket("ws://targets.monitor.spookelton.net");