mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-10 16:47:05 +08:00
Compare commits
2 Commits
a09c5d162b
...
e28944aae4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e28944aae4 | ||
|
|
4218569663 |
@ -95,9 +95,8 @@ type Context struct {
|
||||
// the browser to send this cookie along with cross-site requests.
|
||||
sameSite http.SameSite
|
||||
|
||||
internalContextMu sync.RWMutex
|
||||
internalContext context.Context
|
||||
internalContextCancelCause context.CancelCauseFunc
|
||||
internalContextMu sync.RWMutex
|
||||
internalContext context.Context
|
||||
}
|
||||
|
||||
/************************************/
|
||||
@ -1425,7 +1424,7 @@ func (c *Context) WithInternalContext(ctx context.Context) {
|
||||
c.internalContextMu.Lock()
|
||||
defer c.internalContextMu.Unlock()
|
||||
|
||||
c.internalContext, c.internalContextCancelCause = context.WithCancelCause(ctx)
|
||||
c.internalContext = ctx
|
||||
}
|
||||
|
||||
// InternalContext provides the currently stored internal context in a thread safe manner.
|
||||
|
||||
14
gin.go
14
gin.go
@ -674,20 +674,6 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
c.Request = req
|
||||
c.reset()
|
||||
|
||||
// If we're using internalContext then we need to pass on errors from the request context
|
||||
if c.useInternalContext() {
|
||||
reqCtx := req.Context()
|
||||
go func() {
|
||||
<-reqCtx.Done()
|
||||
if err := reqCtx.Err(); err != nil {
|
||||
c.internalContextMu.RLock()
|
||||
defer c.internalContextMu.RUnlock()
|
||||
|
||||
c.internalContextCancelCause(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
engine.handleHTTPRequest(c)
|
||||
|
||||
engine.pool.Put(c)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user