Merge pull request #2219 from beck-8/fix/context-done-race

fix: avoid data race when watching request cancellation
This commit is contained in:
Luis Pater
2026-03-23 22:57:21 +08:00
committed by GitHub

View File

@@ -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():
}
}()
}