Commit 82b811d
committed
bug symfony#51666 [RateLimiter] CompoundLimiter was accepting requests even when some limiters already consumed all tokens (10n)
This PR was merged into the 6.3 branch.
Discussion
----------
[RateLimiter] CompoundLimiter was accepting requests even when some limiters already consumed all tokens
| Q | A
| ------------- | ---
| Branch? | 6.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
CompoundLimiter is accepting requests when the limit was reached previously.
When processing the limiters and the first one consumes exactly all the remaining tokens (remaining=0, accepted=true) and the next one already reached the limit previously (remaining=0, accepted=0) the $minimalRateLimit is considered the first one that will accept the request (even if it's not the most restrictive).
For example:
CompoundLimiter includes 2 limiters:
- limiter 1 - remaining 2 tokens
- limiter 2 - remaining 0 tokens
After consuming 2 tokens each each limiter generates to limits:
- `limiter1`->consume(2), generates a limit indicating `0` remaining tokens, **accepts** the request (it was last permitted)
- `limiter2`->consume(2), generates a limit indicating `0` remaining tokens, **did not accept** the request (it did not have 2 tokens to satisfy the request)
Because both of them have at this moment `0` remaining tokens, the minimum limit that is returned will be the limit from the `limiter1` . This means that the CompundLimiter will accept the request, even if the `limiter2` should be more restrictive.
If we switch the order in the constructor, the request will be denied. The order should not matter.
Commits
-------
65ce7f8 [RateLimiter] CompoundLimiter was accepting requests even when some limiters already consumed all tokensFile tree
2 files changed
+43
-9
lines changed- src/Symfony/Component/RateLimiter
- Tests
2 files changed
+43
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
Lines changed: 38 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
44 | | - | |
45 | 51 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
49 | 81 | | |
50 | | - | |
51 | | - | |
52 | 82 | | |
53 | 83 | | |
54 | 84 | | |
| |||
0 commit comments