mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-18 22:14:23 +01:00
Fix relay connections metrics
This commit is contained in:
@@ -28,9 +28,11 @@ const limiter = new TTLCache<string, number>();
|
||||
|
||||
/** Set up the Websocket connection. */
|
||||
function connectStream(socket: WebSocket, ip: string | undefined) {
|
||||
let opened = false;
|
||||
const controllers = new Map<string, AbortController>();
|
||||
|
||||
socket.onopen = () => {
|
||||
opened = true;
|
||||
relayConnectionsGauge.inc();
|
||||
};
|
||||
|
||||
@@ -61,7 +63,9 @@ function connectStream(socket: WebSocket, ip: string | undefined) {
|
||||
};
|
||||
|
||||
socket.onclose = () => {
|
||||
relayConnectionsGauge.dec();
|
||||
if (opened) {
|
||||
relayConnectionsGauge.dec();
|
||||
}
|
||||
|
||||
for (const controller of controllers.values()) {
|
||||
controller.abort();
|
||||
|
||||
Reference in New Issue
Block a user