Skip to content

RETRY_AFTER is null in Lease object in case of SlidingWindow rate limiter #131175

Closed

Description

@ValentinVadasz

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

According to the documentation:

retryAfter can be used with the TokenBucketRateLimiter, FixedWindowLimiter, and SlidingWindowLimiter because these algorithms are able to estimate when more permits will be added.

However, when I use a SlidingWindowLimiter, the RETRY_AFTER metadata is null in the lease object.
The RETRY_AFTER metadata name is present in the MetadataNames enumerable, but the _retryAfter field behind it is null.

Register the rate limiter:

rateLimiterOptions.AddSlidingWindowLimiter("rateLimiterName", options =>
{
    options.PermitLimit = rateLimiterConfiguration.PermitLimit;
    options.Window = TimeSpan.FromSeconds(rateLimiterConfiguration.TimeWindowInSeconds);
    options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
    options.SegmentsPerWindow = 10;
});

Read the RETRY_AFTER:

rateLimiterOptions.OnRejected = (context, cancellationToken) =>
{
    if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
    {
        context.HttpContext.Response.Headers.RetryAfter =
            ((int)retryAfter.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo);
    }
};

Expected Behavior

On SlidingWindowLease object, _retryAfter field should be estimated and populated.

Steps To Reproduce

Github repo

Exceptions (if any)

No response

.NET Version

net7.0, net8.0

Anything else?

No response

Activity

  1. changed the title [-]RETRY_AFTER is null on Lease object in case of SlidingWindow rate limiter[/-] [+]RETRY_AFTER is null in Lease object in case of SlidingWindow rate limiter[/+] on Nov 27, 2023
  2. lonix1 commented on Oct 18, 2024

    @lonix1

    Agreed: this is bug, and also is documented incorrectly.

    Without the retry property, the sliding window limiter is effectively useless in most use cases.

    Can someone please label it as a bug, as it seems to have been forgotten?

    Also, could it be fixed for v9?

  3. sandeep-vemula commented on Feb 22, 2025

    @sandeep-vemula

    seems, this is still not fixed. Anyone able to find any workaround on this or any alternate package?

  4. thomotron commented on Aug 21, 2025

    @thomotron

    I ran into this issue today as well.

    Looking at the rate limiter itself it seems that the SlidingWindowLease, despite having a constructor which accepts the retry after TimeSpan, is never actually given a value for it. The lease acquisition process uses two static lease instances which are created with a null timespan.

    If this is truly not supposed to be implemented then the documentation ought to be updated to reflect that, but the fact SlidingWindowLease has a constructor explicitly defined to accept a TimeSpan suggests otherwise.

  5. dotnet-policy-service commented on Jul 21, 2026

    @dotnet-policy-service
    Contributor

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

  6. BrennanConroy commented on Jul 21, 2026

    @BrennanConroy
    Member

    I think this was just an oversight. If someone is interested in fixing this feel free to open a PR and ping me for review. I assume we'll be able to copy from FixedWindowLimiter.

  7. nwoolls commented on Jul 22, 2026

    @nwoolls
    Contributor

    @BrennanConroy ping - I've staged a PR that seems to address this oversight.

  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 22, 2026
  9. added this to the 11.0.0 milestone on Jul 22, 2026
  10. added a commit that references this issue on Aug 4, 2026
    67ca917
  11. added
    Priority:2Work that is important, but not critical for the release
    on Aug 4, 2026
  12. added a commit that references this issue on Aug 14, 2026
    0cfd407
  13. locked and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releasearea-System.Threadinghelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions