mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-16 16:17:38 +03:00
Properly track connection start time and per-connection request num
This commit is contained in:
@@ -205,11 +205,12 @@ type RequestCtx struct {
|
||||
|
||||
id uint64
|
||||
|
||||
lastReadDuration time.Duration
|
||||
|
||||
connRequestNum uint64
|
||||
connTime time.Time
|
||||
|
||||
time time.Time
|
||||
lastReadDuration time.Duration
|
||||
time time.Time
|
||||
|
||||
logger ctxLogger
|
||||
s *Server
|
||||
@@ -686,10 +687,10 @@ func (s *Server) getConcurrency() int {
|
||||
|
||||
func (s *Server) serveConn(c net.Conn) error {
|
||||
currentTime := time.Now()
|
||||
connTime := currentTime
|
||||
connRequestNum := uint64(0)
|
||||
|
||||
ctx := s.acquireCtx(c)
|
||||
ctx.connRequestNum = 0
|
||||
ctx.connTime = currentTime
|
||||
var br *bufio.Reader
|
||||
var bw *bufio.Writer
|
||||
|
||||
@@ -698,7 +699,7 @@ func (s *Server) serveConn(c net.Conn) error {
|
||||
var errMsg string
|
||||
for {
|
||||
ctx.id++
|
||||
ctx.connRequestNum++
|
||||
connRequestNum++
|
||||
ctx.time = currentTime
|
||||
|
||||
if s.ReadTimeout > 0 {
|
||||
@@ -736,6 +737,8 @@ func (s *Server) serveConn(c net.Conn) error {
|
||||
break
|
||||
}
|
||||
|
||||
ctx.connRequestNum = connRequestNum
|
||||
ctx.connTime = connTime
|
||||
ctx.time = currentTime
|
||||
ctx.Response.Reset()
|
||||
s.Handler(ctx)
|
||||
@@ -744,7 +747,7 @@ func (s *Server) serveConn(c net.Conn) error {
|
||||
ctx = s.acquireCtx(c)
|
||||
ctx.Error(errMsg, StatusRequestTimeout)
|
||||
}
|
||||
if s.MaxRequestsPerConn > 0 && ctx.connRequestNum >= uint64(s.MaxRequestsPerConn) {
|
||||
if s.MaxRequestsPerConn > 0 && connRequestNum >= uint64(s.MaxRequestsPerConn) {
|
||||
ctx.SetConnectionClose()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user