Merge c58089110a51c9e0fa585c5a1c962ca989251359 into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9

This commit is contained in:
Samiul Sk 2026-08-23 15:21:42 +05:30 committed by GitHub
commit ba0393f7dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -776,6 +776,29 @@ func TestContextCopyNilErrorsAndAccepted(t *testing.T) {
assert.Nil(t, cp.Accepted)
}
func TestContextCopyRace(t *testing.T) {
c := &Context{}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
for range 1000 {
c.Set("foo", "bar")
}
}()
go func() {
defer wg.Done()
for range 1000 {
c.Copy()
}
}()
wg.Wait()
}
func TestContextHandlerName(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest}