Skip to content

Commit

Permalink
Ensure that socket reconnection is not triggered multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Oct 13, 2024
1 parent bc241de commit b7ad044
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b7ad044

Please sign in to comment.