Commit c8b1474
committed
fix: make daily export limit check atomic to prevent concurrent requests bypassing quota
The export limit check used a non-atomic pattern: read the current count
from Redis, check if it exceeds the daily maximum, then increment. Two
concurrent requests arriving simultaneously could both read the same
count (0 if it was a fresh day), both pass the limit check (0 < 1 or 5),
and both increment, resulting in a count of 2 despite a quota of 1 or 5.
Use a Lua script to atomically check and increment the quota counter in
a single Redis round-trip. The script is executed atomically on the
server, ensuring only one request sees a sub-limit count at a time.
Concurrent requests now correctly queue and are rejected once the limit
is reached, preventing quota bypass.
Closes #255
Signed-off-by: Anshul Jain <anshul23102@iiitd.ac.in>1 parent ec6e78e commit c8b1474
1 file changed
Lines changed: 26 additions & 6 deletions
Lines changed: 26 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
52 | 72 | | |
53 | 73 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
57 | 77 | | |
58 | 78 | | |
59 | 79 | | |
| |||
0 commit comments