From fd2b202037445be8addf48afd96f15f27a943de9 Mon Sep 17 00:00:00 2001 From: douxu Date: Thu, 22 Jan 2026 16:19:00 +0800 Subject: [PATCH] optimize code of websocket close handler --- handler/real_time_data_pull.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/handler/real_time_data_pull.go b/handler/real_time_data_pull.go index c190ff1..5b298ae 100644 --- a/handler/real_time_data_pull.go +++ b/handler/real_time_data_pull.go @@ -60,6 +60,15 @@ func PullRealTimeDataHandler(c *gin.Context) { ctx, cancel := context.WithCancel(c.Request.Context()) defer cancel() + conn.SetCloseHandler(func(code int, text string) error { + logger.Info(c.Request.Context(), "websocket processor shutdown trigger", + "clientID", clientID, "code", code, "reason", text) + + // call cancel to notify other goroutines to stop working + cancel() + return nil + }) + // TODO[BACKPRESSURE-ISSUE] 先期使用固定大容量对扇入模型进行定义 #1 fanInChan := make(chan network.RealTimePullTarget, constants.FanInChanMaxSize) sendChan := make(chan []network.RealTimePullTarget, constants.SendChanBufferSize)