Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Panic in Timeout middleware is causing application to exit #1794

Closed
maciej-jezierski opened this issue Mar 1, 2021 · 0 comments · Fixed by #1795 or open-telemetry/opentelemetry-go-contrib#617 · May be fixed by evantorrie/opentelemetry-go-contrib#648

Comments

@maciej-jezierski
Copy link

I enable recently timeout middleware: https://echo.labstack.com/middleware/timeout for my testing server. I've noticed once it triggered application is going down.

Configuration

Version 4.2.0

e := echo.New()
	renderer := &Template{
		templates: template.Must(template.New("").Funcs(template.FuncMap{
			"safe": func(s string) template.HTMLAttr {
				return template.HTMLAttr(s)
			},
			"meta": func(s api.Tag) template.HTML {
				return template.HTML("<meta " + s.Key + "=\"" + s.Name + "\"  " + s.Type + "=\"" + s.Content + "\" data-vue-router-controlled />")
			},
		}).ParseGlob("web/dist/*.html")),
	}
	e.Renderer = renderer

	e.Pre(middleware.HTTPSRedirect())
	e.Pre(middleware.HTTPSNonWWWRedirect())
	e.Use(middleware.RemoveTrailingSlashWithConfig(middleware.TrailingSlashConfig{
		RedirectCode: http.StatusMovedPermanently,
	}))

	e.Use(middleware.Recover())
	e.Use(middleware.SecureWithConfig(middleware.SecureConfig{
		ReferrerPolicy: "no-referrer",
	}))
	e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
		Format: "method=${method}, uri=${uri}, status=${status}\n",
	}))
	e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
		Timeout: 60 * time.Second,
	}))
	e.Logger.Fatal(e.StartTLS(":1323", "fullchain.pem", "privkey.pem"))

Stacktrace

panic: Write called after Handler finished

goroutine 12657 [running]:
net/http.(*http2responseWriter).write(0xc00056c840, 0x8000, 0xc00070e000, 0x8000, 0x8000, 0x0, 0x0, 0x8000, 0x8000, 0x0)
	/snap/go/7013/src/net/http/h2_bundle.go:6244 +0x1f7
net/http.(*http2responseWriter).Write(0xc00056c840, 0xc00070e000, 0x8000, 0x8000, 0xc00072f958, 0x4acf63, 0xc00056c858)
	/snap/go/7013/src/net/http/h2_bundle.go:6233 +0x56
github.com/labstack/echo/v4.(*Response).Write(0xc0005d0540, 0xc00070e000, 0x8000, 0x8000, 0x8000, 0x0, 0x0)
	/home/maciej/go/pkg/mod/github.com/labstack/echo/v4@v4.2.0/response.go:75 +0x69
io.copyBuffer(0xb63320, 0xc0005d0540, 0xb63580, 0xc0001b6ba0, 0xc00070e000, 0x8000, 0x8000, 0xa5c440, 0x0, 0xb63320)
	/snap/go/7013/src/io/io.go:411 +0x206
io.Copy(...)
	/snap/go/7013/src/io/io.go:368
io.CopyN(0xb63320, 0xc0005d0540, 0xb63b20, 0xc00056c858, 0x94104, 0x0, 0x0, 0x0)
	/snap/go/7013/src/io/io.go:344 +0x9a
net/http.serveContent(0xb6e860, 0xc0005d0540, 0xc0000b1a00, 0xc0001701ac, 0x10, 0x2d97886f, 0xed794cad9, 0xeca460, 0xc0004accb8, 0xb69780, ...)
	/snap/go/7013/src/net/http/fs.go:300 +0x2af
net/http.ServeContent(0xb6e860, 0xc0005d0540, 0xc0000b1a00, 0xc0001701ac, 0x10, 0x2d97886f, 0xed794cad9, 0xeca460, 0xb69780, 0xc00056c858)
	/snap/go/7013/src/net/http/fs.go:167 +0xd8
github.com/labstack/echo/v4.(*context).File(0xc0001cd360, 0xc000170180, 0x3c, 0x0, 0x0)
	/home/maciej/go/pkg/mod/github.com/labstack/echo/v4@v4.2.0/context.go:590 +0x1f4
webkomiksy.pl/m/api.pageImage(0xc00038e000, 0xb79e40, 0xc0001cd360, 0xc000673f50, 0x10, 0x0, 0x0)
	/home/maciej/projects/website/api/image.go:56 +0x219
webkomiksy.pl/m/api.(*Env).Image(0xc00038e000, 0xb79e40, 0xc0001cd360, 0xc0004c3000, 0xc00003ff30)
	/home/maciej/projects/website/api/image.go:21 +0x1a9
github.com/labstack/echo/v4.(*Echo).add.func1(0xb79e40, 0xc0001cd360, 0x5, 0xc00056c801)
	/home/maciej/go/pkg/mod/github.com/labstack/echo/v4@v4.2.0/echo.go:536 +0x62
main.main.func5.1(0xb79e40, 0xc0001cd360, 0xc00056c840, 0xadac68)
	/home/maciej/projects/website/server.go:105 +0x1ad
github.com/labstack/echo/v4/middleware.TimeoutWithConfig.func1.1.1(0xc0005d0780, 0xc000021ba0, 0xb79e40, 0xc0001cd360)
	/home/maciej/go/pkg/mod/github.com/labstack/echo/v4@v4.2.0/middleware/timeout.go:67 +0x3a
created by github.com/labstack/echo/v4/middleware.TimeoutWithConfig.func1.1
	/home/maciej/go/pkg/mod/github.com/labstack/echo/v4@v4.2.0/middleware/timeout.go:64 +0x230

Expected behavior

The server will continue to work after a timeout on the request

Actual behavior

Server is going down

aldas added a commit to aldas/echo that referenced this issue Mar 1, 2021
@aldas aldas changed the title Timeout middleware is causing application to exit Panic in Timeout middleware is causing application to exit Mar 1, 2021
aldas added a commit that referenced this issue Mar 2, 2021
@lammel lammel added this to the v4.2.1 milestone Mar 3, 2021
This was referenced Mar 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants