fix: use a rwlock to avoid concurrent map read and write#210
Conversation
Codecov Report
@@ Coverage Diff @@
## main #210 +/- ##
==========================================
- Coverage 58.84% 58.71% -0.14%
==========================================
Files 55 55
Lines 2243 2248 +5
==========================================
Hits 1320 1320
- Misses 864 869 +5
Partials 59 59
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| } | ||
|
|
||
| mh.countersMutex.Lock() | ||
| defer mh.countersMutex.Unlock() |
There was a problem hiding this comment.
So we think AddToRequestCount is racing with CreateRequestCount? But if I look at the code it looks like CreateRequestCount would have had to happen first as part init of WrapHandler?
Also we don't really need a map here right? Because we have a static set of metrics and can precreate counters?
There was a problem hiding this comment.
This made me think about how this is designed and I agree with you. I need to maybe get rid of the map and switch to static counters. I had a map because I thought there would be more counters we would add but we do not need a map if we can reference the counters directly.
Description
Fixing a crash caused by concurrent read and write of map
Testing
Local Tests
Checklist: