diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2019-10-04 00:06:37 +0200 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-10-04 00:06:37 +0200 |
commit | 9e3020fb037b87e8fa82ea307e16c554008fcbbc (patch) | |
tree | 5257385872fde33015e7a683ac1441180d1977d2 | |
parent | Try to find what goes wrong (diff) | |
download | fasthttp-aws-unexpected-eof.tar.gz fasthttp-aws-unexpected-eof.tar.bz2 fasthttp-aws-unexpected-eof.zip |
Ignore more io.ErrUnexpectedEOF, print more debug infoaws-unexpected-eof
-rw-r--r-- | server.go | 12 | ||||
-rw-r--r-- | workerpool.go | 7 | ||||
-rw-r--r-- | workerpool_test.go | 6 |
3 files changed, 13 insertions, 12 deletions
@@ -1770,7 +1770,7 @@ func (s *Server) ServeConn(c net.Conn) error { atomic.AddInt32(&s.open, 1) - err := s.serveConn(c) + _, err := s.serveConn(c) atomic.AddUint32(&s.concurrency, ^uint32(0)) @@ -1831,15 +1831,15 @@ func (s *Server) idleTimeout() time.Duration { return s.ReadTimeout } -func (s *Server) serveConn(c net.Conn) error { +func (s *Server) serveConn(c net.Conn) (int, error) { defer atomic.AddInt32(&s.open, -1) if proto, err := s.getNextProto(c); err != nil { - return err + return 0, err } else { handler, ok := s.nextProtos[proto] if ok { - return handler(c) + return 0, handler(c) } } @@ -1953,7 +1953,7 @@ func (s *Server) serveConn(c net.Conn) error { } if err != nil { - if err == io.EOF { + if err == io.EOF || err == io.ErrUnexpectedEOF { err = nil } else if nr, ok := err.(errNothingRead); ok { if connRequestNum > 1 { @@ -2136,7 +2136,7 @@ func (s *Server) serveConn(c net.Conn) error { } s.releaseCtx(ctx) } - return err + return int(connRequestNum), err } func (s *Server) setState(nc net.Conn, state ConnState) { diff --git a/workerpool.go b/workerpool.go index e73cfcd..4feaa7f 100644 --- a/workerpool.go +++ b/workerpool.go @@ -16,7 +16,7 @@ import ( type workerPool struct { // Function for serving server connections. // It must leave c unclosed. - WorkerFunc ServeHandler + WorkerFunc func(c net.Conn) (int, error) MaxWorkersCount int @@ -211,13 +211,14 @@ func (wp *workerPool) workerFunc(ch *workerChan) { start := time.Now() - if err = wp.WorkerFunc(c); err != nil && err != errHijacked { + var n int + if n, err = wp.WorkerFunc(c); err != nil && err != errHijacked { errStr := err.Error() if wp.LogAllErrors || !(strings.Contains(errStr, "broken pipe") || strings.Contains(errStr, "reset by peer") || strings.Contains(errStr, "request headers: small read buffer") || strings.Contains(errStr, "i/o timeout")) { - wp.Logger.Printf("error when serving connection %q<->%q after %v: %s", c.LocalAddr(), c.RemoteAddr(), time.Since(start), err) + wp.Logger.Printf("error when serving connection %q<->%q after %v and %d requests: %s", c.LocalAddr(), c.RemoteAddr(), time.Since(start), n, err) } } if err == errHijacked { diff --git a/workerpool_test.go b/workerpool_test.go index 05e1be0..e0f1342 100644 --- a/workerpool_test.go +++ b/workerpool_test.go @@ -33,7 +33,7 @@ func TestWorkerPoolStartStopConcurrent(t *testing.T) { func testWorkerPoolStartStop(t *testing.T) { wp := &workerPool{ - WorkerFunc: func(conn net.Conn) error { return nil }, + WorkerFunc: func(conn net.Conn) (int, error) { return 0, nil }, MaxWorkersCount: 10, Logger: defaultLogger, } @@ -74,7 +74,7 @@ func testWorkerPoolMaxWorkersCountMulti(t *testing.T) { func testWorkerPoolMaxWorkersCount(t *testing.T) { ready := make(chan struct{}) wp := &workerPool{ - WorkerFunc: func(conn net.Conn) error { + WorkerFunc: func(conn net.Conn) (int, error) { buf := make([]byte, 100) n, err := conn.Read(buf) if err != nil { @@ -90,7 +90,7 @@ func testWorkerPoolMaxWorkersCount(t *testing.T) { <-ready - return nil + return 0, nil }, MaxWorkersCount: 10, Logger: defaultLogger, |