8000 panic not recovery · Issue #2049 · gin-gonic/gin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
panic not recovery #2049
Open
Open
@yyq2013

Description

@yyq2013
  • 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.
  • go version:
    build go version go1.12.7 linux/amd64

  • gin version (or commit ref):

  • operating system:
    in docker(from scracth) which run centos 3.10.0-514.10.2.el7.x86_64 update Readme.md. Add code to String method #1 SMP Fri Mar 3 00:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Description

My function is very simple, if a client close http connection, then my backend log stream need close at same time:

router := gin.Default()
router.GET("/live", logController.Stream)

func StreamLog(client logClient, c *gin.Context) {
	rs, err := client.Stream()
	if err != nil {
		c.String(http.StatusInternalServerError, err.Error())
		return
	}
	defer rs.Close()

	go func() {
		<-c.Writer.CloseNotify()
		log.Println("client closed")
	}()
	sc := bufio.NewScanner(rs)
	c.Stream(func(w io.Writer) bool {
		if sc.Scan() {
			w.Write(sc.Bytes())
			w.Write([]byte("\n"))
		}
		return sc.Err() == nil
	})
}

and the gin http server crash in some access cases as following, gin should catch this panic in the recovery() middleware IMO:

panic: net/http: CloseNotify called after ServeHTTP finished

goroutine 2675 [running]:
net/http.(*response).CloseNotify(0xc0003a4620, 0x16532c0)
        /go/src/net/http/server.go:1955 +0x5f
github.com/gin-gonic/gin.(*responseWriter).CloseNotify(0xc0001162c0, 0x1)
        /tmp/pkg/mod/github.com/gin-gonic/gin@v1.4.0/response_writer.go:112 +0x57
livelog/web.StreamLog.func1(0xc0001162c0, 0x1637340, 0xc000342160)
        /tmp/src/livelog/web/util.go:49 +0x38
created by livelog/web.StreamLog
        /tmp/src/livelog/web/util.go:48 +0x133

Screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0