Repository navigation
Commit 6bbc6c3
Fix CapacityLimiter over-granting tokens on asyncio (#1172)
On the asyncio backend, releasing a token notified the next waiter but did not reserve the token for it until that waiter resumed. A non-blocking acquire issued in that window saw an empty wait queue and a borrower count
below the limit, so it slipped through, leaving borrowed_tokens greater than total_tokens and available_tokens negative.
Reserve the freed token for the woken waiter the moment its event is set (in _notify_next_waiter and when increasing total_tokens), mirroring the Semaphore/Lock hand-off, so the non-blocking acquire correctly raises
WouldBlock. The woken waiter no longer re-adds itself on resume, and a waiter cancelled after being granted the token now releases it to the next in line.
Fixes #1170.
---------
Co-authored-by: Alex Grönholm <[email protected]>1 parent 6f82b25 commit 6bbc6c3
3 files changed
Lines changed: 41 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2077 | 2077 | | |
2078 | 2078 | | |
2079 | 2079 | | |
2080 | | - | |
| 2080 | + | |
| 2081 | + | |
2081 | 2082 | | |
2082 | 2083 | | |
2083 | 2084 | | |
| |||
2090 | 2091 | | |
2091 | 2092 | | |
2092 | 2093 | | |
2093 | | - | |
| 2094 | + | |
2094 | 2095 | | |
2095 | | - | |
| 2096 | + | |
| 2097 | + | |
2096 | 2098 | | |
2097 | 2099 | | |
2098 | 2100 | | |
| |||
2124 | 2126 | | |
2125 | 2127 | | |
2126 | 2128 | | |
| 2129 | + | |
2127 | 2130 | | |
2128 | 2131 | | |
2129 | 2132 | | |
2130 | | - | |
2131 | | - | |
2132 | 2133 | | |
2133 | 2134 | | |
2134 | 2135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
993 | 993 | | |
994 | 994 | | |
995 | 995 | | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
0 commit comments