From b2921518ace134117a9b08967a05afba5fdea18d Mon Sep 17 00:00:00 2001 From: beck-8 <1504068285@qq.com> Date: Thu, 19 Mar 2026 00:15:52 +0800 Subject: [PATCH] fix: avoid data race when watching request cancellation --- sdk/api/handlers/handlers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/api/handlers/handlers.go b/sdk/api/handlers/handlers.go index 0e490e32..28ab970d 100644 --- a/sdk/api/handlers/handlers.go +++ b/sdk/api/handlers/handlers.go @@ -339,12 +339,13 @@ func (h *BaseAPIHandler) GetContextWithCancel(handler interfaces.APIHandler, c * } } newCtx, cancel := context.WithCancel(parentCtx) + cancelCtx := newCtx if requestCtx != nil && requestCtx != parentCtx { go func() { select { case <-requestCtx.Done(): cancel() - case <-newCtx.Done(): + case <-cancelCtx.Done(): } }() }