We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
While writing to response header in goroutines we get fatal error: concurrent map writes.
package main import ( "sync" "github.com/gin-gonic/gin" ) func setHeader(c *gin.Context) { c.Header("key", "value") } func main() { g := gin.Default() g.GET("/hello", func(c *gin.Context) { wg := sync.WaitGroup{} go func() { wg.Add(1) defer wg.Done() for i := 0; i < 100000; i++ { setHeader(c) } }() go func() { wg.Add(1) defer wg.Done() for i := 0; i < 100000; i++ { setHeader(c) } }() wg.Wait() }) g.Run(":9000") }
$ curl http://localhost:9000/hello Should not crash
fatal error: concurrent map writes goroutine 25 [running]: net/textproto.MIMEHeader.Set(...) /opt/homebrew/Cellar/go/1.22.5/libexec/src/net/textproto/header.go:22 net/http.Header.Set(...) /opt/homebrew/Cellar/go/1.22.5/libexec/src/net/http/header.go:40 github.com/gin-gonic/gin.(*Context).Header(0x0?, {0x1002fe555, 0x3}, {0x1002fedc8, 0x5}) /Users/admin/go/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:897 +0xb0 main.setHeader(...) /Users/admin/repos/scripts/main.go:12 main.main.func1.1() /Users/admin/repos/scripts/main.go:23 +0x94 created by main.main.func1 in goroutine 23 /Users/admin/repos/scripts/main.go:19 +0x7c
The text was updated successfully, but these errors were encountered:
For this reason, I suggest that the application side solve it.
#4101 (comment)
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Description
While writing to response header in goroutines we get fatal error: concurrent map writes.
How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: