Panic on aborted requests to properly close the connection

This commit is contained in:
Anton Bartsits 2024-10-25 15:44:04 +02:00 committed by GitHub
parent edc0a52b5a
commit 27948493aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 143 additions and 16 deletions

View file

@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v2/pkg/middlewares/capture"
"github.com/traefik/traefik/v2/pkg/middlewares/recovery"
"github.com/traefik/traefik/v2/pkg/types"
)
@ -948,8 +947,14 @@ func doLoggingWithAbortedStream(t *testing.T, config *types.AccessLog) {
req = req.WithContext(reqContext)
chain := alice.New()
chain = chain.Append(func(next http.Handler) (http.Handler, error) {
return recovery.New(context.Background(), next)
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
defer func() {
_ = recover() // ignore the stream backend panic to avoid the test to fail.
}()
next.ServeHTTP(rw, req)
}), nil
})
chain = chain.Append(capture.Wrap)
chain = chain.Append(WrapHandler(logger))