From be2ffbcd0ce32c5d2c6ec1701d20735dc51329d6 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Wed, 8 May 2024 10:12:50 -0600 Subject: [PATCH] Fix tracking websocket connections (#26943) --- server/channels/app/platform/web_conn.go | 7 +++++++ server/channels/app/platform/web_hub.go | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/channels/app/platform/web_conn.go b/server/channels/app/platform/web_conn.go index dd1dc80be7..542ffe8f00 100644 --- a/server/channels/app/platform/web_conn.go +++ b/server/channels/app/platform/web_conn.go @@ -417,8 +417,15 @@ func (wc *WebConn) Pump() { func (wc *WebConn) readPump() { defer func() { + if metrics := wc.Platform.metricsIFace; metrics != nil { + metrics.DecrementHTTPWebSockets(wc.originClient) + } wc.WebSocket.Close() }() + if metrics := wc.Platform.metricsIFace; metrics != nil { + metrics.IncrementHTTPWebSockets(wc.originClient) + } + wc.WebSocket.SetReadLimit(model.SocketMaxMessageSizeKb) wc.WebSocket.SetReadDeadline(time.Now().Add(pongWaitTime)) wc.WebSocket.SetPongHandler(func(string) error { diff --git a/server/channels/app/platform/web_hub.go b/server/channels/app/platform/web_hub.go index 6d0cc10a2b..4dab982c41 100644 --- a/server/channels/app/platform/web_hub.go +++ b/server/channels/app/platform/web_hub.go @@ -423,9 +423,6 @@ func (h *Hub) Start() { connIndex.Add(webConn) atomic.StoreInt64(&h.connectionCount, int64(connIndex.AllActive())) - if metrics := h.platform.metricsIFace; metrics != nil { - metrics.IncrementHTTPWebSockets(webConn.originClient) - } if webConn.IsAuthenticated() && webConn.reuseCount == 0 { // The hello message should only be sent when the reuseCount is 0. @@ -440,9 +437,6 @@ func (h *Hub) Start() { webConn.active.Store(false) atomic.StoreInt64(&h.connectionCount, int64(connIndex.AllActive())) - if metrics := h.platform.metricsIFace; metrics != nil { - metrics.DecrementHTTPWebSockets(webConn.originClient) - } if webConn.UserId == "" { continue