mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
Added LogAllErrors config parameter to Server, which allows logging the most frequent errors such as 'connection reset by peer', 'broken pipe' and 'i/o timeout'. By default such errors are suppressed
This commit is contained in:
@@ -201,6 +201,16 @@ type Server struct {
|
||||
// Server accepts all the requests by default.
|
||||
GetOnly bool
|
||||
|
||||
// Logs all errors, including the most frequent
|
||||
// 'connection reset by peer', 'broken pipe' and 'connection timeout'
|
||||
// errors. Such errors are common in production serving real-world
|
||||
// clients.
|
||||
//
|
||||
// By default the most frequent errors such as
|
||||
// 'connection reset by peer', 'broken pipe' and 'connection timeout'
|
||||
// are suppressed in order to limit output log traffic.
|
||||
LogAllErrors bool
|
||||
|
||||
// Logger, which is used by RequestCtx.Logger().
|
||||
//
|
||||
// By default standard logger from log package is used.
|
||||
@@ -1062,6 +1072,7 @@ func (s *Server) Serve(ln net.Listener) error {
|
||||
wp := &workerPool{
|
||||
WorkerFunc: s.serveConn,
|
||||
MaxWorkersCount: maxWorkersCount,
|
||||
LogAllErrors: s.LogAllErrors,
|
||||
Logger: s.logger(),
|
||||
}
|
||||
wp.Start()
|
||||
|
||||
+5
-4
@@ -19,10 +19,10 @@ type workerPool struct {
|
||||
// It must leave c unclosed.
|
||||
WorkerFunc func(c net.Conn) error
|
||||
|
||||
// Maximum number of workers to create.
|
||||
MaxWorkersCount int
|
||||
|
||||
// Logger used by workerPool.
|
||||
LogAllErrors bool
|
||||
|
||||
Logger Logger
|
||||
|
||||
lock sync.Mutex
|
||||
@@ -194,8 +194,9 @@ func (wp *workerPool) workerFunc(ch *workerChan) {
|
||||
}
|
||||
if err = wp.WorkerFunc(c); err != nil && err != errHijacked {
|
||||
errStr := err.Error()
|
||||
if !strings.Contains(errStr, "broken pipe") && !strings.Contains(errStr, "reset by peer") &&
|
||||
!strings.Contains(errStr, "i/o timeout") {
|
||||
if wp.LogAllErrors || !(strings.Contains(errStr, "broken pipe") ||
|
||||
strings.Contains(errStr, "reset by peer") ||
|
||||
strings.Contains(errStr, "i/o timeout")) {
|
||||
wp.Logger.Printf("error when serving connection %q<->%q: %s", c.LocalAddr(), c.RemoteAddr(), err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user