Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent race condition when updating rate limit data
Previously if you made two requests simultaneously there was a chance that the rate limit data would get messed up. Specifically, consider the following scenario: 1. A new rate limit window starts, with 100 requests remaining. 1. Two requests are made (A and B) 2. Request A is completed first, so now there are 99 requests left, but is delayed in the network 3. Request B completes second, reducing the remaining count to 98, but takes a faster path back 4. Response B is processed first, and the rate limit data is set to 98 remaining. 5. Response A is processed, and the rate limit is updated to 99 left. Clearly this is incorrect. This is a very minor inconsistency, as the next request will overwrite the value, but it still has the potential to confuse any algorithms that expect the value to monotonically decrease during a period.
- Loading branch information