- go version: go version go1.14.1 darwin/amd64
- gin version (or commit ref): 1.6.3
- operating system:
2020/06/12 14:27:43 http: panic serving 127.0.0.1:52658: write tcp 127.0.0.1:80->127.0.0.1:52658: write: broken pipe
goroutine 34342467 [running]:
net/http.(*conn).serve.func1(0xc00024dae0)
/usr/local/go/src/net/http/server.go:1772 +0x139
panic(0x1071f40, 0xc001250f00)
/usr/local/go/src/runtime/panic.go:975 +0x3e3
github.com/gin-gonic/gin/render.JSON.Render(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/render/json.go:59
github.com/gin-gonic/gin.(*Context).Render(0xc0008490e0, 0x1f4, 0x138dfe0, 0xc000ebdcf0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:841 +0x146
github.com/gin-gonic/gin.(*Context).JSON(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:884
pkg.poizon.com/golang/go-common/globally.(*Handler).RecoveryWithLogger.func1.1(0xc0008490e0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/globally/handler.go:53 +0x370
panic(0x1071f40, 0xc001250f00)
/usr/local/go/src/runtime/panic.go:969 +0x166
github.com/gin-gonic/gin/render.JSON.Render(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/render/json.go:59
github.com/gin-gonic/gin.(*Context).Render(0xc0008490e0, 0xc8, 0x138dfe0, 0xc000ebdb50)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:841 +0x146
github.com/gin-gonic/gin.(*Context).JSON(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:884
pkg.poizon.com/golang/go-common/gin_controller.(*Controller).Response(0xc000402420, 0xc0008490e0, 0xf84fc0, 0xc001094bc0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/gin_controller/controller.go:48 +0x17a
pkg.poizon.com/sns/sns-content/pkg/controllers.(*ContentController).Detail(0xc000402420, 0xc0008490e0)
/drone/src/pkg/controllers/content.go:44 +0x16a
github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b
pkg.poizon.com/golang/go-common/server.(*GinServer).Localizer(0xc0000a4360, 0xc0008490e0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/server/server.go:164 +0x1d9
github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b
pkg.poizon.com/golang/go-common/tracer.(*TracerServer).MiddlewareTracerFunc(0xc0007803f0, 0xc0008490e0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/tracer/server.go:87 +0x651
github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b
pkg.poizon.com/golang/go-common/server.(*Prometheus).HandlerFunc.func1(0xc0008490e0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/server/prometheus.go:325 +0xbc
github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b
pkg.poizon.com/golang/go-common/globally.(*Access).GinZap.func1(0xc0008490e0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/globally/access.go:37 +0xfad
github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b
pkg.poizon.com/golang/go-common/globally.(*Handler).RecoveryWithLogger.func1(0xc0008490e0)
/go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/globally/handler.go:67 +0x4e
github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc0001f4a00, 0xc0008490e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:409 +0x666
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc0001f4a00, 0x1395ee0, 0xc00138c2a0, 0xc000d2ae00)
/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:367 +0x14d
net/http.serverHandler.ServeHTTP(0xc0006f6000, 0x1395ee0, 0xc00138c2a0, 0xc000d2ae00)
/usr/local/go/src/net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00024dae0, 0x139b4e0, 0xc000f09c80)
/usr/local/go/src/net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2933 +0x35c
Comment From: krasin
FWIW, this panic was introduced in https://github.com/gin-gonic/gin/pull/781.
Comment From: aaronjheng
It has been a long time. http.ResponseWriter.Write() error just be paniced.
Comment From: aaronjheng
By the way,recovery middleware can help.
Comment From: arvinatwork
Any ideas how to prevent panic on this line? We're encountering this on our service whenever a query takes too long to complete (which is acceptable sometimes in our use case). We can adjust the write timeout to a longer duration but I think it's better to prevent this panic from happening.
Or is it possible to use custom recovery to send a custom error response than 502? Is there a timeline on when it will be released?
Comment From: johnsonsuncrypto
- go version: go version go1.14.1 darwin/amd64
- gin version (or commit ref): 1.6.3
- operating system:
2020/06/12 14:27:43 http: panic serving 127.0.0.1:52658: write tcp 127.0.0.1:80->127.0.0.1:52658: write: broken pipe goroutine 34342467 [running]: net/http.(*conn).serve.func1(0xc00024dae0) /usr/local/go/src/net/http/server.go:1772 +0x139 panic(0x1071f40, 0xc001250f00) /usr/local/go/src/runtime/panic.go:975 +0x3e3 github.com/gin-gonic/gin/render.JSON.Render(...) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/render/json.go:59 github.com/gin-gonic/gin.(*Context).Render(0xc0008490e0, 0x1f4, 0x138dfe0, 0xc000ebdcf0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:841 +0x146 github.com/gin-gonic/gin.(*Context).JSON(...) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:884 pkg.poizon.com/golang/go-common/globally.(*Handler).RecoveryWithLogger.func1.1(0xc0008490e0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/globally/handler.go:53 +0x370 panic(0x1071f40, 0xc001250f00) /usr/local/go/src/runtime/panic.go:969 +0x166 github.com/gin-gonic/gin/render.JSON.Render(...) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/render/json.go:59 github.com/gin-gonic/gin.(*Context).Render(0xc0008490e0, 0xc8, 0x138dfe0, 0xc000ebdb50) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:841 +0x146 github.com/gin-gonic/gin.(*Context).JSON(...) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:884 pkg.poizon.com/golang/go-common/gin_controller.(*Controller).Response(0xc000402420, 0xc0008490e0, 0xf84fc0, 0xc001094bc0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/gin_controller/controller.go:48 +0x17a pkg.poizon.com/sns/sns-content/pkg/controllers.(*ContentController).Detail(0xc000402420, 0xc0008490e0) /drone/src/pkg/controllers/content.go:44 +0x16a github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b pkg.poizon.com/golang/go-common/server.(*GinServer).Localizer(0xc0000a4360, 0xc0008490e0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/server/server.go:164 +0x1d9 github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b pkg.poizon.com/golang/go-common/tracer.(*TracerServer).MiddlewareTracerFunc(0xc0007803f0, 0xc0008490e0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/tracer/server.go:87 +0x651 github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b pkg.poizon.com/golang/go-common/server.(*Prometheus).HandlerFunc.func1(0xc0008490e0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/server/prometheus.go:325 +0xbc github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b pkg.poizon.com/golang/go-common/globally.(*Access).GinZap.func1(0xc0008490e0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/globally/access.go:37 +0xfad github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b pkg.poizon.com/golang/go-common/globally.(*Handler).RecoveryWithLogger.func1(0xc0008490e0) /go/pkg/mod/pkg.poizon.com/golang/go-common@v0.0.0-20200608152559-b4436c72198f/globally/handler.go:67 +0x4e github.com/gin-gonic/gin.(*Context).Next(0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 +0x3b github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc0001f4a00, 0xc0008490e0) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:409 +0x666 github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc0001f4a00, 0x1395ee0, 0xc00138c2a0, 0xc000d2ae00) /go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:367 +0x14d net/http.serverHandler.ServeHTTP(0xc0006f6000, 0x1395ee0, 0xc00138c2a0, 0xc000d2ae00) /usr/local/go/src/net/http/server.go:2807 +0xa3 net/http.(*conn).serve(0xc00024dae0, 0x139b4e0, 0xc000f09c80) /usr/local/go/src/net/http/server.go:1895 +0x86c created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2933 +0x35c
is there some solution about this error, i have see #781 , it seems have no relation with this panic
Comment From: benja-wu
- go version: go.18
- gin version: v1.6.3
- operation system: darwin/amd64
We reproduced this panic in the Live env, it was recovery by using middleware.
IMHO, this write: broken pipe
error is common when the user actively close the website(tcp connection) before our backend responds. Or in some backend slow processing scenarios.
Propose to replace this panic
with a usual error
return in this render.JSON
implementation.
Comment From: Cweiping
I also reproduced this kind of panic
- go : 1.18/linux/amd64
- gin: v1.7.7