diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index 02d2995e..bed6453f 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -28,9 +28,11 @@ const limiter = new TTLCache(); /** Set up the Websocket connection. */ function connectStream(socket: WebSocket, ip: string | undefined) { + let opened = false; const controllers = new Map(); 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();