From b4152d1a992acd8e257c11cc29b5eab98faae483 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 1 Apr 2022 15:54:02 +0200 Subject: [PATCH] Only set RequestCtx.s once We have a RequestCtx pool per server so we only need to set it once. This fixes a race codition where acquireCtx would assign .s while .Done() is reading it. Even though acquireCtx would always set it to the same, already assigned, value it would still trigger the race detector. Fixes: https://github.com/valyala/fasthttp/issues/1261 --- server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.go b/server.go index bc5324725f..a970e82760 100644 --- a/server.go +++ b/server.go @@ -2634,11 +2634,11 @@ func (s *Server) acquireCtx(c net.Conn) (ctx *RequestCtx) { ctx = new(RequestCtx) ctx.Request.keepBodyBuffer = keepBodyBuffer ctx.Response.keepBodyBuffer = keepBodyBuffer + ctx.s = s } else { ctx = v.(*RequestCtx) } - ctx.s = s ctx.c = c return ctx