Do not create a logger instance for each proxy
This commit is contained in:
parent
c19cf125e8
commit
c5b92b5260
1 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue