Skip to content

Commit

Permalink
Fix context.Copy race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Gavache committed Jul 18, 2017
1 parent 7180f2b commit 52958eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (c *Context) Copy() *Context {
cp.Writer = &cp.writermem
cp.index = abortIndex
cp.handlers = nil
cp.Keys = map[string]interface{}{}
for k, v := range c.Keys {
cp.Keys[k] = v
}
return &cp
}

Expand Down
2 changes: 2 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func TestContextCopy(t *testing.T) {
assert.Equal(t, cp.Keys, c.Keys)
assert.Equal(t, cp.engine, c.engine)
assert.Equal(t, cp.Params, c.Params)
cp.Set("foo", "notBar")
assert.False(t, cp.Keys["foo"] == c.Keys["foo"])
}

func TestContextHandlerName(t *testing.T) {
Expand Down

0 comments on commit 52958eb

Please sign in to comment.