-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
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
fatal error: concurrent map writes #15
Comments
What is your version? |
|
@xtony77 I can't reproduce the issue |
@xtony77 OK. I will take a look. |
I was able to reproduce the bug but the chance is very rare for me. However, when I change the sleep duration of the Code: r.GET("/timeout", timeout.New(timeout.WithTimeout(200*time.Microsecond),
timeout.WithHandler(func(c *gin.Context) {
time.Sleep(199 * time.Microsecond)
c.JSON(http.StatusOK, gin.H{
"code": 200,
"data": "",
})
}),
timeout.WithResponse(func(c *gin.Context) {
c.JSON(http.StatusRequestTimeout, gin.H{
"code": 408,
"message": "test",
})
}))) |
Actually, I use This proves that 2 gotoutine are operating with |
- fatal error: concurrent map writes(gin-contrib#15)
Try below codes, it can stability reproduce this case: package main
import (
"log"
"net/http"
"time"
"github.com/gin-contrib/timeout"
"github.com/gin-gonic/gin"
)
func main() {
g := gin.Default()
g.Use(timeout.New(
timeout.WithTimeout(time.Second),
timeout.WithHandler(func(ctx *gin.Context) {
ctx.Next()
}),
))
g.GET("/", func(ctx *gin.Context) {
for {
ctx.Header("foo", "bar")
}
})
serv := &http.Server{
Addr: ":1997",
Handler: g,
}
if err := serv.ListenAndServe(); err != nil {
log.Fatal(err)
}
} the crash output:
|
- fatal error: concurrent map writes(gin-contrib#15)
If set the handler time.Sleep same as the timeout, there is a chance to reproduce this error!
Here is gin panic code line:
https://github.com/gin-gonic/gin/blob/580e7da6eed01e2926de1240ec31f6473cd1a2af/render/render.go#L38
There is also a chance of combined http results:
I can't think of a solution at the moment, does anyone have any good ideas?
The text was updated successfully, but these errors were encountered: