Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State active #1260

Merged
merged 3 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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