Compare commits

..

2 Commits

12
gin.go
View File

@ -677,13 +677,17 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// If we're using internalContext then we need to pass on errors from the request context
if c.useInternalContext() {
reqCtx := req.Context()
// we need to get the cancelCause function now, so that we have the function for this request
// because the c is a pointer to a Context that will possibly go back into the pool and be reused
c.internalContextMu.RLock()
cancelCause := c.internalContextCancelCause
c.internalContextMu.RUnlock()
go func() {
<-reqCtx.Done()
if err := reqCtx.Err(); err != nil {
c.internalContextMu.RLock()
defer c.internalContextMu.RUnlock()
c.internalContextCancelCause(err)
cancelCause(err)
}
}()
}