Skip to content

Commit 62c15a5

Browse files
Don't reset RequestCtx.s (#1234)
RequestCtx's are reused in a server specific pool, so no need to reset it. This fixes a use after reset but when RequestCtx is use as context. Fixes #1205
1 parent 7670c6e commit 62c15a5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,14 @@ func (ctx *RequestCtx) reset() {
788788
ctx.connTime = zeroTime
789789
ctx.remoteAddr = nil
790790
ctx.time = zeroTime
791-
ctx.s = nil
792791
ctx.c = nil
793792

793+
// Don't reset ctx.s!
794+
// We have a pool per server so the next time this ctx is used it
795+
// will be assigned the same value again.
796+
// ctx might still be in use for context.Done() and context.Err()
797+
// which are safe to use as they only use ctx.s and no other value.
798+
794799
if ctx.timeoutResponse != nil {
795800
ctx.timeoutResponse.Reset()
796801
}

0 commit comments

Comments
 (0)