Skip to content

Initial overview of how the RetryAfter metadata should be set and tested#124478

Draft
asbjornvad wants to merge 2 commits intodotnet:mainfrom
asbjornvad:#92557-RetryAfter_Ratelimiting
Draft

Initial overview of how the RetryAfter metadata should be set and tested#124478
asbjornvad wants to merge 2 commits intodotnet:mainfrom
asbjornvad:#92557-RetryAfter_Ratelimiting

Conversation

@asbjornvad
Copy link

This commit solves the issue of wrongly returned RetryAfter value, however only in the FixedWindowRateLimiter.
It shows how it could be tested.

The queue is not taken into consideration in this implementation.
There are no new tests since this is a draft.

#92557

…ted.

This commit solves the issue of wrongly returned RetryAfter value, however only in the FixedWindowRateLimiter.
It shows how it should be used tested.

The queue is not taken into consideration in this implementation.

dotnet#92557
Copilot AI review requested due to automatic review settings February 16, 2026 20:26
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 16, 2026
@asbjornvad
Copy link
Author

@dotnet-policy-service agree

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to fix issue #92557 where the FixedWindowRateLimiter incorrectly returns the full window duration as the Retry-After value instead of the remaining time until the next window. The implementation changes the CreateFailedWindowLease method to calculate the remaining time by subtracting the elapsed time from the window duration.

Changes:

  • Modified CreateFailedWindowLease to calculate remaining time instead of returning static window multiples
  • Added a test-injectable function field to control elapsed time behavior for testing
  • Updated test assertions to reflect the new expected behavior
  • Added a test helper method to manipulate elapsed time in tests

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.

File Description
src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs Adds injectable getElapsedTime function field; reimplements CreateFailedWindowLease to calculate remaining window time; comments out original queue-aware implementation
src/libraries/System.Threading.RateLimiting/tests/FixedWindowRateLimiterTests.cs Adds SetElapsedTime helper for testing; updates test expectations; adds calls to set elapsed time to 0 in multiple tests

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

…ideration the CoPilot suggestions. Not all suggestions were valid.

Added 2 tests, one to test partially elapsed window and one where the whole window has elapsed, but hasnt been refreshed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Threading community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants