From 13b808c1e44e32b560db6a6db92fcdb6c3a2155a Mon Sep 17 00:00:00 2001 From: Damos chen Date: Thu, 5 Mar 2026 20:17:16 +0800 Subject: [PATCH] fix(mcp-session): send SSE endpoint event via local goroutine InjectData (#3567) --- plugins/golang-filter/mcp-session/common/sse.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/golang-filter/mcp-session/common/sse.go b/plugins/golang-filter/mcp-session/common/sse.go index 5a6085c2b..3c7af82a8 100644 --- a/plugins/golang-filter/mcp-session/common/sse.go +++ b/plugins/golang-filter/mcp-session/common/sse.go @@ -140,10 +140,16 @@ func (s *SSEServer) HandleSSE(cb api.FilterCallbackHandler, stopChan chan struct // Send the initial endpoint event initialEvent := fmt.Sprintf("event: endpoint\ndata: %s\n\n", messageEndpoint) - err = s.redisClient.Publish(channel, initialEvent) - if err != nil { - api.LogErrorf("Failed to send initial event: %v", err) - } + go func() { + defer func() { + if r := recover(); r != nil { + api.LogErrorf("Failed to send initial event: %v", r) + } + }() + defer cb.EncoderFilterCallbacks().RecoverPanic() + api.LogDebugf("SSE Send message: %s", initialEvent) + cb.EncoderFilterCallbacks().InjectData([]byte(initialEvent)) + }() // Start health check handler go func() {