Merge pull request #2219 from beck-8/fix/context-done-race
fix: avoid data race when watching request cancellation
This commit is contained in:
@@ -339,12 +339,13 @@ func (h *BaseAPIHandler) GetContextWithCancel(handler interfaces.APIHandler, c *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
newCtx, cancel := context.WithCancel(parentCtx)
|
newCtx, cancel := context.WithCancel(parentCtx)
|
||||||
|
cancelCtx := newCtx
|
||||||
if requestCtx != nil && requestCtx != parentCtx {
|
if requestCtx != nil && requestCtx != parentCtx {
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-requestCtx.Done():
|
case <-requestCtx.Done():
|
||||||
cancel()
|
cancel()
|
||||||
case <-newCtx.Done():
|
case <-cancelCtx.Done():
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user