Fix relay connections metrics

This commit is contained in:
Alex Gleason 2024-08-03 08:18:53 -05:00
parent 5ac1abdf69
commit 950adb25c6
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -28,9 +28,11 @@ const limiter = new TTLCache<string, number>();
/** Set up the Websocket connection. */ /** Set up the Websocket connection. */
function connectStream(socket: WebSocket, ip: string | undefined) { function connectStream(socket: WebSocket, ip: string | undefined) {
let opened = false;
const controllers = new Map<string, AbortController>(); const controllers = new Map<string, AbortController>();
socket.onopen = () => { socket.onopen = () => {
opened = true;
relayConnectionsGauge.inc(); relayConnectionsGauge.inc();
}; };
@ -61,7 +63,9 @@ function connectStream(socket: WebSocket, ip: string | undefined) {
}; };
socket.onclose = () => { socket.onclose = () => {
relayConnectionsGauge.dec(); if (opened) {
relayConnectionsGauge.dec();
}
for (const controller of controllers.values()) { for (const controller of controllers.values()) {
controller.abort(); controller.abort();