Description

I got this error when using a client app to get data from a gin server, and I am not sure what causing it:

2022/07/08 13:54:35 [Recovery] 2022/07/08 - 13:54:35 panic recovered:
GET /api/search/recipes?query=100&_=1657306457936 HTTP/1.1
Host: 192.168.17.17:8000
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-US
Connection: Keep-Alive
Ua-Cpu: AMD64
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; rv:11.0) like Gecko


write tcp 192.168.17.17:8000->192.168.48.40:58806: wsasend: An existing connection was forcibly closed by the remote host.
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/render/json.go:58 (0x7ff762b0f9be)
        JSON.Render: panic(err)
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:910 (0x7ff762b53177)
        (*Context).Render: if err := r.Render(c.Writer); err != nil {
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:953 (0x7ff762c8782c)
        (*Context).JSON: c.Render(code, render.JSON{Data: obj})
C:/MultiTech-Projects/GO Source Code Files/Web-Applications/Wails/info-hub-server/app.go:395 (0x7ff762c87665)
        searchRecipesByQuery: c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "results": resultData, "msg": "success", "error": ""})
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x7ff762b5ba41)
        (*Context).Next: c.handlers[c.index](c)
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/recovery.go:101 (0x7ff762b5ba2c)
        CustomRecoveryWithWriter.func1: c.Next()
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x7ff762ca39f2)
        (*Context).Next: c.handlers[c.index](c)
C:/MultiTech-Projects/GO Source Code Files/Web-Applications/Wails/info-hub-server/app.go:1673 (0x7ff762ca39cf)
        (*App).customRequestLogger.func1: c.Next()
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x7ff762b5a890)
        (*Context).Next: c.handlers[c.index](c)
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:616 (0x7ff762b5a4f8)
        (*Engine).handleHTTPRequest: c.Next()
C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:572 (0x7ff762b5a03c)
        (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
C:/Program Files/Go/src/net/http/server.go:2916 (0x7ff762934ada)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
C:/Program Files/Go/src/net/http/server.go:1966 (0x7ff76292fad6)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
C:/Program Files/Go/src/runtime/asm_amd64.s:1571 (0x7ff7626a59a0)
        goexit: BYTE    $0x90   // NOP

[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 200 with 500
2022/07/08 13:54:35 http: panic serving 192.168.48.40:58806: write tcp 192.168.17.17:8000->192.168.48.40:58806: wsasend: An existing connection was forcibly closed by the remote host.
goroutine 75 [running]:
net/http.(*conn).serve.func1()
        C:/Program Files/Go/src/net/http/server.go:1825 +0xbf
panic({0x7ff762f54540, 0xc000392410})
        C:/Program Files/Go/src/runtime/panic.go:844 +0x258
github.com/gin-gonic/gin/render.JSON.Render(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/render/json.go:58
github.com/gin-gonic/gin.(*Context).Render(0xc000412200, 0x1f4, {0x7ff763a140f8, 0xc000407a40})
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:910 +0xf8
github.com/gin-gonic/gin.(*Context).JSON(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:953
main.(*App).createGinRouter.func2(0xc000412200, {0x7ff762f54540?, 0xc000392410?})
        C:/MultiTech-Projects/GO Source Code Files/Web-Applications/Wails/info-hub-server/app.go:242 +0x32f
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1.1()
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/recovery.go:97 +0x2cc
panic({0x7ff762f54540, 0xc000392410})
        C:/Program Files/Go/src/runtime/panic.go:838 +0x207
github.com/gin-gonic/gin/render.JSON.Render(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/render/json.go:58
github.com/gin-gonic/gin.(*Context).Render(0xc000412200, 0xc8, {0x7ff763a140f8, 0xc0003468e0})
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:910 +0xf8
github.com/gin-gonic/gin.(*Context).JSON(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:953
main.searchRecipesByQuery(0x2030000?)
        C:/MultiTech-Projects/GO Source Code Files/Web-Applications/Wails/info-hub-server/app.go:395 +0x50d
github.com/gin-gonic/gin.(*Context).Next(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1(0xc000412200)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/recovery.go:101 +0x82
github.com/gin-gonic/gin.(*Context).Next(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
main.(*App).customRequestLogger.func1(0xc000412200)
        C:/MultiTech-Projects/GO Source Code Files/Web-Applications/Wails/info-hub-server/app.go:1673 +0x93
github.com/gin-gonic/gin.(*Context).Next(...)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000504b60, 0xc000412200)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:616 +0x671
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000504b60, {0x7ff763a14dc0?, 0xc0003ea460}, 0xc0000fa800)
        C:/Users/vho/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:572 +0x1dd
net/http.serverHandler.ServeHTTP({0xc0003c49c0?}, {0x7ff763a14dc0, 0xc0003ea460}, 0xc0000fa800)
        C:/Program Files/Go/src/net/http/server.go:2916 +0x43b
net/http.(*conn).serve(0xc0003b0960, {0x7ff763a155b8, 0xc000141080})
        C:/Program Files/Go/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
        C:/Program Files/Go/src/net/http/server.go:3071 +0x4db
  • go version: v1.18.3
  • gin version (or commit ref): v1.8.1
  • operating system: Windows 10

I have been searching on Google for solutions, but still, I cannot figure out what's the issue. Is it anything to to with using TLS older version other than TLS 1.2? My client app still get the data from the server, but it quite slower than I expected.

Comment From: ghost

I have a similar problem, but when I download the Gin package.

go get -v -u github.com/gin-gonic/gin
 go: module github.com/gin-gonic/gin: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/list": read tcp 
 10.211.1.3:2589->142.250.80.113:443: wsarecv: An existing connection was forcibly closed by the remote host.

Comment From: KiddoV

My gin handler has a connection with the database and it will return some data to the frontend. The gin handler is a search feature so it will be a lot of traffic going on here (client app will call this handler every time user try to put something in the search bar). At first, I SELECT * (all) from a table and I think that make gin slow. So I minimize the Select by only select some columns that will be used and that error is no more now.

I am closing this issue because my problem was solved.