Skip to content

Commit

Permalink
When StreamRequestBody is set to true, we cannot safely release `…
Browse files Browse the repository at this point in the history
…br`. (#1844)

For example, when using chunked encoding, it's possible that `br` has only read the request headers.
  • Loading branch information
newacorn authored Aug 31, 2024
1 parent 3aa972e commit d31f4ef
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,9 @@ func (s *Server) serveConn(c net.Conn) (err error) {
err = ctx.Request.readLimitBody(br, maxRequestBodySize, s.GetOnly, !s.DisablePreParseMultipartForm)
}
}

if (s.ReduceMemoryUsage && br.Buffered() == 0) || err != nil {
// When StreamRequestBody is set to true, we cannot safely release br.
// For example, when using chunked encoding, it's possible that br has only read the request headers.
if (!s.StreamRequestBody && s.ReduceMemoryUsage && br.Buffered() == 0) || err != nil {
releaseReader(s, br)
br = nil
}
Expand Down Expand Up @@ -2358,7 +2359,7 @@ func (s *Server) serveConn(c net.Conn) (err error) {
} else {
err = ctx.Request.ContinueReadBody(br, maxRequestBodySize, !s.DisablePreParseMultipartForm)
}
if (s.ReduceMemoryUsage && br.Buffered() == 0) || err != nil {
if (!s.StreamRequestBody && s.ReduceMemoryUsage && br.Buffered() == 0) || err != nil {
releaseReader(s, br)
br = nil
}
Expand Down

0 comments on commit d31f4ef

Please sign in to comment.