From c0be2b6caac5675c00d871de0648b2bb018ec317 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Thu, 4 Dec 2025 12:12:24 +0800 Subject: [PATCH] cleanup HTTP proxy session when device disconnects Previously, when a device disconnected, the associated HTTP proxy session remained in the httpProxySessions store, causing a memory leak. This commit adds a goroutine that monitors the context cancellation and automatically deletes the session from the store when ctx.Done() is triggered. This ensures proper cleanup of proxy sessions when devices disconnect, preventing resource accumulation over time. Signed-off-by: Jianhui Zhao --- http.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/http.go b/http.go index ec62d0a..720cd34 100644 --- a/http.go +++ b/http.go @@ -340,6 +340,11 @@ func httpProxyRedirect(a *APIServer, c *gin.Context, group string) { ses.Expire() httpProxySessions.Store(sid, ses) + go func() { + <-ctx.Done() + httpProxySessions.Delete(sid) + }() + log.Debug().Msgf(`new httpProxySession "%s" for device "%s"`, sid, devid) domain := c.Request.Header.Get("HttpProxyRedirDomain")