mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-04 01:38:12 +08:00
fix: move Keys read inside RLock in Context.Copy() to prevent data race
Copy() reads c.Keys before acquiring the read lock, then clones the stale reference under the lock. If another goroutine calls Set() between the read and the lock acquisition, the cKeys variable may reference a map being concurrently modified. This is particularly dangerous on the first Set() call where c.Keys transitions from nil to a new map allocation.
This commit is contained in:
parent
d3ffc99852
commit
e7c8e50895
@ -132,9 +132,8 @@ func (c *Context) Copy() *Context {
|
||||
cp.handlers = nil
|
||||
cp.fullPath = c.fullPath
|
||||
|
||||
cKeys := c.Keys
|
||||
c.mu.RLock()
|
||||
cp.Keys = maps.Clone(cKeys)
|
||||
cp.Keys = maps.Clone(c.Keys)
|
||||
c.mu.RUnlock()
|
||||
|
||||
cParams := c.Params
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user