Skip to content

Commit

Permalink
State active (#1260)
Browse files Browse the repository at this point in the history
* Require at least Go 1.15

* Fix StateActive state

* Don't panic when idle connections get closed
  • Loading branch information
erikdubbelboer authored Apr 1, 2022
1 parent f3bce3a commit d4c739e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/valyala/fasthttp

go 1.12
go 1.15

require (
github.com/andybalholm/brotli v1.0.4
Expand Down
13 changes: 5 additions & 8 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4c739e

Please sign in to comment.