Fix context.Params race condition on Copy() (#1841)

* Fix context.Params race condition on Copy()

Using context.Param(key) on a context.Copy inside a goroutine
may lead to incorrect value on a high load, where another request
overwrite a Param

* Using waitgroup to wait asynchronous test case
This commit is contained in:
Samuel Abreu
2019-05-27 03:04:30 -03:00
committed by 田欧
parent 35e33d3638
commit 6e320c97e8
2 changed files with 26 additions and 0 deletions

View File

@ -89,6 +89,9 @@ func (c *Context) Copy() *Context {
for k, v := range c.Keys {
cp.Keys[k] = v
}
paramCopy := make([]Param, len(cp.Params))
copy(paramCopy, cp.Params)
cp.Params = paramCopy
return &cp
}