Commit 0e25328
committed
fix: drain _seen_logs in a while loop so drift can't inflate the cap
Under free-threaded (3.14t) contention or sustained multi-instance
sync use, two callers can both pass the ``len(seen) < _MAX_SEEN_LOGS``
check and both insert before either evicts — leaving the dict
transiently above the cap. The previous ``if``-based eviction
removed one entry on the next call, but the new insert added one
back, so the overshoot never drained and the dict silently grew
with thread count.
Switch the eviction to ``while len(seen) >= _MAX_SEEN_LOGS:`` so a
single non-racing caller drains the accumulated drift back to the
cap. Bail on ``RuntimeError`` and ``StopIteration`` so a concurrent
mutation can't make the loop spin.
Add ``test_mark_seen_drains_drift_above_cap`` to pin the drain
behaviour — a regression to single-eviction would leave the dict
at ``cap + drift - 1`` and fail the assertion.1 parent ebe1ab2 commit 0e25328
2 files changed
Lines changed: 32 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
108 | 129 | | |
109 | 130 | | |
110 | 131 | | |
| |||
0 commit comments