Description
^[[31m2021/09/10 16:05:00 [Recovery] 2021/09/10 - 16:05:00 panic recovered:
write tcp xxx.xxx.xxx.xxx:61234->xxx.xxx.xxx.xxx:18446: i/o timeout
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/render/json.go:59 (0x97d926)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:841 (0x984288)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:884 (0xa2f16e)
/usr/local/gslb-sdcp/pkg/api/lake.go:174 (0xa2f0fe)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 (0x994150)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/recovery.go:83 (0x994137)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 (0x9931d3)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/logger.go:241 (0x993192)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/context.go:161 (0x98a30f)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:409 (0x98a2f6)
/root/golang/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:367 (0x989dac)
/usr/local/go/src/net/http/server.go:2887 (0x718962)
/usr/local/go/src/net/http/server.go:1952 (0x713d8c)
/usr/local/go/src/runtime/asm_amd64.s:1371 (0x46f320)
How to reproduce
ctx.JSON(http.StatusOK, data)
Environment
- go version: 1.15
- gin version (or commit ref): v1.6.3
- operating system:CentOS Linux release 7.7.1908 (Core)
Comment From: eljoth
@thinkerou may I wonder why you closed this issue ? I am experiencing the same issue with the following setup:
1.2.3.4:8080 -- Gin service 2.3.4.5:8080 -- Nginx service (k8s ingress controler)
(Can assure, both services were up and running)
Request: simple get request Gin version: v1.7.3
Error message:
[31m2021/11/02 13:24:18 [Recovery] 2021/11/02 - 13:24:18 panic recovered:
write tcp 1.2.3.4:8080->2.3.4.5:8080: i/o timeout
Comment From: qiandu2006
I met this same issue. So I debug it, and I found where panic happened
// github.com/gin-gonic/gin/render/json.go
...
// Render (JSON) writes data with custom ContentType.
func (r JSON) Render(w http.ResponseWriter) (err error) {
if err = WriteJSON(w, r.Data); err != nil {
panic(err)
}
return
}
And the error message is really clear,
http: panic serving 10.195.0.28:36520: write tcp 10.195.0.28:8082->10.195.0.28:36520: i/o timeout
So the solution is to set a bigger ReadTimeout and WriteTimeout for http.Server
server := &http.Server{
// ...
ReadTimeout: readTimeout, // make it bigger
WriteTimeout: writeTimeout, // make it bigger
// ...
}
Done.