Commit 30756f2
authored
chore(release): 0.17.0 (rebuild) — +circuit-breaker lock unification (#102)
* fix(sdk): unify circuit breaker lock — use sync Lock for both paths
DEF-CB-LOCK-UNIFICATION-2026-09-12
Pre-fix the sync path held `self._lock` (threading.Lock) and the
async path held a separate `asyncio.Lock` (`_async_lock`,
lazy-init via `_get_async_lock`). On the same breaker instance,
a sync thread calling `breaker.call(sync_func, ...)` and an
async coroutine calling `await breaker.call(async_func, ...)`
could both write `self._state` concurrently — the two locks
provided no mutual exclusion across the sync/async boundary.
The async critical sections (`_on_failure_async` and
`_on_success_async`) contain NO `await` between attribute
writes. With asyncio's single-threaded execution, those sections
are already atomic by GIL+scheduler — the `_async_lock` was
dead weight providing no additional exclusion beyond what asyncio
already gives.
Fix: removed `_async_lock` and `_get_async_lock`. Both paths
now use `self._lock` (threading.Lock). A sync write and an
async write now serialise against each other.
`async with self._lock` blocks the event loop for zero
observable time on the happy path (no `await` in the
critical section). Trade-off: sync+async exclusion > minor
lock-hold latency. This is the point of the fix.
Three source-pin regression tests in
`tests/test_circuit_breaker_branches.py`:
* `test_async_lock_attribute_removed` — pins that
`_async_lock` is gone.
* `test_no_get_async_lock_method` — pins that
`_get_async_lock` is gone.
* `test_concurrent_sync_async_state_not_corrupt` — spins a
sync thread + an async coroutine on the same instance,
asserts `_failure_count == total_failures` (every increment
is paired on the same lock acquisition) and `state == OPEN`
when `_failure_count >= threshold` (no writer clobbers).
Verification:
- SDK pytest: 1807 passed, 4 skipped (+3 new)
- ruff clean
- mypy clean on all 37 source files
- Rebuilt wheel (nullrun-0.17.0) installed in nullrun-examples
venv; runtime verified to have `_async_lock` and
`_get_async_lock` removed, `self._lock` present.
Hot-path impact: bounded — only bites when user code mixes sync
and async `breaker.call()` on the same instance. Mitigation
already in place: Redis publish of OPEN/HALF_OPEN keeps
cross-process workers consistent. The fix tightens the
in-process invariant.
* docs(changelog): add DEF-CB-LOCK-UNIFICATION-2026-09-12 to 0.17.0 block
Cherry-picked 77bf38b onto the release/0.17.0 rebuild branch to include
the circuit-breaker lock unification fix. Update the 0.17.0 Summary to
list the 4th theme, add the Fixed bullet, add the test_circuit_breaker_
branches.py Added bullet, refresh the verification line with the new
test count (1807 passed vs 1797 baseline = 10 new circuit_breaker tests),
and add a 'Why this is needed' paragraph explaining the sync+async
state-write race the fix closes.
No code changes; documentation only.1 parent 2756862 commit 30756f2
3 files changed
Lines changed: 153 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | | - | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
84 | 97 | | |
85 | 98 | | |
86 | 99 | | |
87 | 100 | | |
88 | 101 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 102 | | |
96 | 103 | | |
97 | 104 | | |
| |||
394 | 401 | | |
395 | 402 | | |
396 | 403 | | |
397 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
398 | 416 | | |
399 | | - | |
400 | | - | |
| 417 | + | |
401 | 418 | | |
402 | 419 | | |
403 | 420 | | |
| |||
411 | 428 | | |
412 | 429 | | |
413 | 430 | | |
414 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
415 | 438 | | |
416 | | - | |
417 | | - | |
| 439 | + | |
418 | 440 | | |
419 | 441 | | |
420 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
0 commit comments