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 17, 2017
1 parent 5cb25a6 commit 17ddb4a
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 @@ -82,6 +82,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 @@ -265,6 +265,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 17ddb4a

Please sign in to comment.