From d4c739eee589f96f10f07f05db40f1cfb5ad0bd9 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 1 Apr 2022 10:18:48 +0200 Subject: [PATCH] State active (#1260) * Require at least Go 1.15 * Fix StateActive state * Don't panic when idle connections get closed --- go.mod | 2 +- server.go | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index f5cfe1bbef..a9cd927af6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/valyala/fasthttp -go 1.12 +go 1.15 require ( github.com/andybalholm/brotli v1.0.4 diff --git a/server.go b/server.go index 3ff678ce02..bc5324725f 100644 --- a/server.go +++ b/server.go @@ -2138,7 +2138,7 @@ func (s *Server) serveConn(c net.Conn) (err error) { if connRequestNum > 1 { if d := s.idleTimeout(); d > 0 { if err := c.SetReadDeadline(time.Now().Add(d)); err != nil { - panic(fmt.Sprintf("BUG: error in SetReadDeadline(%s): %s", d, err)) + break } } } @@ -2178,15 +2178,17 @@ func (s *Server) serveConn(c net.Conn) (err error) { ctx.Response.secureErrorLogMessage = s.SecureErrorLogMessage if err == nil { + s.setState(c, StateActive) + if s.ReadTimeout > 0 { if err := c.SetReadDeadline(time.Now().Add(s.ReadTimeout)); err != nil { - panic(fmt.Sprintf("BUG: error in SetReadDeadline(%s): %s", s.ReadTimeout, err)) + break } } else if s.IdleTimeout > 0 && connRequestNum > 1 { // If this was an idle connection and the server has an IdleTimeout but // no ReadTimeout then we should remove the ReadTimeout. if err := c.SetReadDeadline(zeroTime); err != nil { - panic(fmt.Sprintf("BUG: error in SetReadDeadline(zeroTime): %s", err)) + break } } if s.DisableHeaderNamesNormalizing { @@ -2238,11 +2240,6 @@ func (s *Server) serveConn(c net.Conn) (err error) { } } - if err == nil { - // If we read any bytes off the wire, we're active. - s.setState(c, StateActive) - } - if (s.ReduceMemoryUsage && br.Buffered() == 0) || err != nil { releaseReader(s, br) br = nil