swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
374 stars 17 forks source link

Broken pipe should not cause panic in gzip writer #198

Closed vearutop closed 8 months ago

vearutop commented 8 months ago

Describe the bug When HTTP request in canceled on client side, write in progress may fail with broken pipe error. GZIP middleware propagates this error using panic.

To Reproduce Open a browser page that makes many http requests to your server and close the window before the page is fully loaded.

 panic: BUG: cannot close gzip writer: write tcp 127.0.0.1:8008->127.0.0.1:33666: write: broken pipe

 -> github.com/swaggest/rest/response/gzip.Middleware.func1.1
 ->   /home/vearutop/go/pkg/mod/github.com/swaggest/rest@v0.2.65/response/gzip/middleware.go:34

    github.com/swaggest/rest/response/gzip.Middleware.func1
      /home/vearutop/go/pkg/mod/github.com/swaggest/rest@v0.2.65/response/gzip/middleware.go:40
    net/http.HandlerFunc.ServeHTTP
      /home/vearutop/sdk/gotip/src/net/http/server.go:2166
    github.com/bool64/brick.NewBaseLocator.HTTPTraceTransaction.func6.1
      /home/vearutop/go/pkg/mod/github.com/bool64/brick@v0.2.5/log/http.go:30
    net/http.HandlerFunc.ServeHTTP
      /home/vearutop/sdk/gotip/src/net/http/server.go:2166
    go.opencensus.io/plugin/ochttp.(*Handler).ServeHTTP
      /home/vearutop/go/pkg/mod/go.opencensus.io@v0.24.0/plugin/ochttp/server.go:92
    github.com/bool64/brick/opencensus.Middleware.WithRouteTag.func2
      /home/vearutop/go/pkg/mod/go.opencensus.io@v0.24.0/plugin/ochttp/route.go:40
....

Expected behavior Probably such an error should be silently "swallowed", as there is nothing you can do with client resets.