Commit 7a36fcf
Fix PoseHeaderCache race under concurrent Pose.read (#239)
* Fix PoseHeaderCache race under concurrent Pose.read
PoseHeaderCache was global mutable state updated non-atomically: check_cache
could match the old hash while another thread's set_cache had already
replaced the header, and PoseHeader.read re-read end_offset after the check.
Concurrent Pose.read calls on files with different headers could crash
("buffer is too small for requested array") or silently parse a pose with
another file's header.
The cache is now an immutable (hash, header, start_offset, end_offset) tuple
swapped atomically; readers take a single snapshot. The legacy class
attributes are kept in sync for backward compatibility.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Use a lock for PoseHeaderCache instead of an atomic entry tuple
Per review: a plain threading.Lock over check_cache/set_cache/clear_cache
is easier to follow than the snapshot tuple. check_cache still returns
(header, end_offset) -- the offset must come from the same critical
section, otherwise the caller re-reading the class attribute races again.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: autoresearch <autoresearch@local>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 0bbac44 commit 7a36fcf
2 files changed
Lines changed: 54 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
| 242 | + | |
237 | 243 | | |
238 | 244 | | |
239 | 245 | | |
240 | 246 | | |
241 | 247 | | |
242 | 248 | | |
243 | | - | |
244 | | - | |
245 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
246 | 253 | | |
247 | | - | |
248 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
249 | 257 | | |
250 | 258 | | |
251 | 259 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
256 | 265 | | |
257 | 266 | | |
258 | 267 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
263 | 273 | | |
264 | 274 | | |
265 | 275 | | |
| |||
317 | 327 | | |
318 | 328 | | |
319 | 329 | | |
320 | | - | |
321 | | - | |
322 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
323 | 336 | | |
324 | 337 | | |
325 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
340 | 341 | | |
341 | 342 | | |
342 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
343 | 368 | | |
344 | 369 | | |
345 | 370 | | |
| |||
0 commit comments