mirror of
https://github.com/netfun2000/rttys_zhaojh329.git
synced 2026-02-27 09:53:24 +08:00
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:
5
http.go
5
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")
|
||||
|
||||
Reference in New Issue
Block a user