From c3d2a905018977e4a51d3b9d4f1d2c6f5c1da5a3 Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 30 Aug 2025 11:19:56 +0800 Subject: [PATCH] fix(websocket): ensure resources are properly released by closing the manager in PeriodicWrite function --- internal/net/gphttp/websocket/utils.go | 1 + internal/utils/io.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/net/gphttp/websocket/utils.go b/internal/net/gphttp/websocket/utils.go index 3a858857..430f289e 100644 --- a/internal/net/gphttp/websocket/utils.go +++ b/internal/net/gphttp/websocket/utils.go @@ -82,6 +82,7 @@ func PeriodicWrite(c *gin.Context, interval time.Duration, get func() (any, erro c.Error(apitypes.InternalServerError(err, "failed to upgrade to websocket")) return } + defer manager.Close() err = manager.PeriodicWrite(interval, get) if err != nil { c.Error(apitypes.InternalServerError(err, "failed to write to websocket")) diff --git a/internal/utils/io.go b/internal/utils/io.go index f204fa73..70a5bb21 100644 --- a/internal/utils/io.go +++ b/internal/utils/io.go @@ -141,7 +141,7 @@ func getHTTPFlusher(dst io.Writer) flushErrorInterface { const copyBufSize = synk.SizedPoolThreshold -var bytesPool = synk.NewBytesPool() +var bytesPool = synk.GetBytesPool() // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style