Skip to content

Commit

Permalink
fix: change inner req hdr caused race
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Oct 18, 2024
1 parent 8ded9c5 commit 0e20ae2
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions api/pkg/filtermanager/filtermanager_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0e20ae2

Please sign in to comment.