• With issues:
  • Use the search tool before opening a new issue.
  • Please provide source code and commit sha if you found a bug.
  • Review existing issues and provide feedback or react to them.

Description

Access too fast 2021/02/20 22:22:29 write tcp 127.0.0.1:8080->127.0.0.1:54110: write: broken pipe

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    g := gin.Default()
    g.GET("/", func(c *gin.Context) {
        c.Html(200, "123.html", nil)
    })
    g.Run(":9000")
}

Expectations

chrome Access too fast http://127.0.0.1:9000

Actual result

none

Environment

  • go version:1.16
  • gin version (or commit ref):v1.6.3
  • operating system: mac os 11.2.1 (20D74) os x64

Comment From: ankur-lt

Any update here?

Comment From: nikooo777

I am using a nice-recovery yet this broken pipe still manages to trigger a panic that crashes the service. How are people getting around it?

panic: write tcp 127.0.0.1:5569->127.0.0.1:34348: write: broken pipe
github.com/gin-gonic/gin.(*Context).Render(0xc001018100, 0xc8, 0x16cb460, 0xc000ed4390)
        /home/niko/go/pkg/mod/github.com/gin-gonic/gin@v1.7.1/context.go:914 +0x17c
github.com/gin-gonic/gin.(*Context).Data(...)
        /home/niko/go/pkg/mod/github.com/gin-gonic/gin@v1.7.1/context.go:1003
....
panic: write tcp 127.0.0.1:5569->127.0.0.1:34426: write: broken pipe

Comment From: le011

i have the same problem, how to fix it?

http: panic serving ***********: write tcp ********->*********: write: broken pipe
golang/src/net/http/server.go:1767
golang/src/runtime/panic.go:679 +0x1b2
github.com/gin-gonic/gin/render.JSON.Render(...)
    /***/jenkins/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/render/json.go:56

Environment

  • gin 1.7.4
  • golang 1.13
  • os linux

Comment From: nikooo777

I ended up putting this in my handler:

defer func() {
    if r := recover(); r != nil {
        log.Errorf("Recovered from panic: %v", r)
    }
}()

it doesn't really fix it but at least it's a bit cleaner...

Comment From: XieWeiXie

anyone sloved this problem ? i mean , i got the same problem,and i do not known how to fix it .

gin: v1.7.7 go: 1.15

Comment From: EugeneTorap

Hi @XieWeiXie! The issue has been fixed by #2150 PR. Please, upgrade gin to v1.9 and also update the version of golang. @thinkerou @appleboy Could you close this issue?