Commit 4731d40
fix: resolve data race in storagev2 cacheProvider (#173)
* fix: resolve data race in cacheResolver.FeedbackGood method
Create a copy of the cache value instead of modifying it in-place
to avoid race conditions when multiple goroutines access the same
resolverCacheValue concurrently. This fixes the data race detected
by the Go race detector in the storagev2 cacheProvider.
Fixes #172
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: zhangzqs <34616640+zhangzqs@users.noreply.github.com>
* refactor: use RWMutex instead of copying arrays to fix data race
Replace array copying approach with sync.RWMutex for better performance:
- Add RWMutex to resolverCacheValue struct
- Use RLock for concurrent read operations (Resolve, IsValid, ShouldRefresh)
- Use Lock for write operations (FeedbackGood)
- Zero memory allocation overhead
- Better performance in high-frequency call scenarios
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: YangSen-qn <49863787+YangSen-qn@users.noreply.github.com>
* fix: prevent deadlock in IsEqual and improve time consistency in Resolve
1. Fix potential AB-BA deadlock in IsEqual() method:
- Lock mutexes in consistent order based on pointer address
- Prevents deadlock when two goroutines compare same values in reverse order
2. Improve time consistency in Resolve() method:
- Re-capture timestamp after acquiring write lock
- Ensures accurate expiration checks in the cleanup phase
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: YangSen-qn <49863787+YangSen-qn@users.noreply.github.com>
---------
Co-authored-by: xgopilot <noreply@goplus.org>
Co-authored-by: zhangzqs <34616640+zhangzqs@users.noreply.github.com>
Co-authored-by: yangsen <yang_sen_ys@163.com>
Co-authored-by: YangSen-qn <49863787+YangSen-qn@users.noreply.github.com>1 parent dce7b71 commit 4731d40
1 file changed
+37
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| |||
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
| 230 | + | |
228 | 231 | | |
| 232 | + | |
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
| 236 | + | |
| 237 | + | |
232 | 238 | | |
233 | 239 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
240 | 248 | | |
241 | | - | |
242 | | - | |
| 249 | + | |
| 250 | + | |
243 | 251 | | |
244 | 252 | | |
245 | | - | |
| 253 | + | |
| 254 | + | |
246 | 255 | | |
247 | 256 | | |
248 | 257 | | |
| |||
260 | 269 | | |
261 | 270 | | |
262 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
263 | 276 | | |
264 | 277 | | |
265 | 278 | | |
| |||
270 | 283 | | |
271 | 284 | | |
272 | 285 | | |
273 | | - | |
274 | 286 | | |
275 | 287 | | |
276 | 288 | | |
| |||
279 | 291 | | |
280 | 292 | | |
281 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
282 | 305 | | |
283 | 306 | | |
284 | 307 | | |
| |||
293 | 316 | | |
294 | 317 | | |
295 | 318 | | |
| 319 | + | |
| 320 | + | |
296 | 321 | | |
297 | 322 | | |
298 | 323 | | |
299 | 324 | | |
| 325 | + | |
| 326 | + | |
300 | 327 | | |
301 | 328 | | |
302 | 329 | | |
| |||
0 commit comments