diff --git a/pkg/server/service/proxy.go b/pkg/server/service/proxy.go index 13d107a32..8f3c0a418 100644 --- a/pkg/server/service/proxy.go +++ b/pkg/server/service/proxy.go @@ -26,6 +26,12 @@ const StatusClientClosedRequest = 499 // StatusClientClosedRequestText non-standard HTTP status for client disconnection. const StatusClientClosedRequestText = "Client Closed Request" +// errorLogger is a logger instance used to log proxy errors. +// This logger is a shared instance as having one instance by proxy introduces a memory and go routine leak. +// The writer go routine is never stopped as the finalizer is never called. +// See https://github.com/sirupsen/logrus/blob/d1e6332644483cfee14de11099f03645561d55f8/writer.go#L57). +var errorLogger = stdlog.New(log.WithoutContext().WriterLevel(logrus.DebugLevel), "", 0) + func buildProxy(passHostHeader *bool, responseForwarding *dynamic.ResponseForwarding, roundTripper http.RoundTripper, bufferPool httputil.BufferPool) (http.Handler, error) { var flushInterval ptypes.Duration if responseForwarding != nil { @@ -83,7 +89,7 @@ func buildProxy(passHostHeader *bool, responseForwarding *dynamic.ResponseForwar Transport: roundTripper, FlushInterval: time.Duration(flushInterval), BufferPool: bufferPool, - ErrorLog: stdlog.New(log.WithoutContext().WriterLevel(logrus.DebugLevel), "", 0), + ErrorLog: errorLogger, ErrorHandler: func(w http.ResponseWriter, request *http.Request, err error) { statusCode := http.StatusInternalServerError