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 <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2025-12-04 12:12:24 +08:00
parent e4d45638f6
commit c0be2b6caa

View File

@@ -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")