From 0e20ae2f78d5665d3d1582c2499e91d33dc7913c Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 18 Oct 2024 18:58:42 +0800 Subject: [PATCH] fix: change inner req hdr caused race Signed-off-by: spacewander --- api/pkg/filtermanager/filtermanager_dev.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/api/pkg/filtermanager/filtermanager_dev.go b/api/pkg/filtermanager/filtermanager_dev.go index f577e113..85aac872 100644 --- a/api/pkg/filtermanager/filtermanager_dev.go +++ b/api/pkg/filtermanager/filtermanager_dev.go @@ -29,17 +29,11 @@ func (m *filterManager) OnLog(reqHdr capi.RequestHeaderMap, reqTrailer capi.Requ return } - m.hdrLock.Lock() - if m.reqHdr == nil { - m.reqHdr = &filterManagerRequestHeaderMap{ - RequestHeaderMap: reqHdr, - } - } else { - // In our benchmark BenchmarkFilterManagerRegular, reuse the request header wrapper is 5% faster than create a new one, - // even the reusage requires holding the lock though it is running on fast path. - h, _ := m.reqHdr.(*filterManagerRequestHeaderMap) - h.RequestHeaderMap = reqHdr + wrappedReqHdr := &filterManagerRequestHeaderMap{ + RequestHeaderMap: reqHdr, } + m.hdrLock.Lock() + m.reqHdr = wrappedReqHdr m.hdrLock.Unlock() m.runOnLogPhase(m.reqHdr, reqTrailer, rspHdr, rspTrailer) }