Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limitter sample bug/clarification #260

Open
validide opened this issue Sep 5, 2024 · 3 comments
Open

Rate limitter sample bug/clarification #260

validide opened this issue Sep 5, 2024 · 3 comments

Comments

@validide
Copy link

validide commented Sep 5, 2024

Hi,

While looking over the reate limitter documentatin I was looking at the following code sample:

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

        context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
        context.HttpContext.Response.WriteAsync("Too many requests. Please try again later.");

        return new ValueTask();
    };

Is the WriteAsync method call missing the await by design? At first glance this seems as a bug.

@Rick-Anderson
Copy link
Contributor

@Kahbazi @maartenba should we change that to WriteAsync

@maartenba
Copy link
Contributor

Good idea - this indeed should be sync (or use await but I'd vote using the sync version here)

@Kahbazi
Copy link
Member

Kahbazi commented Oct 12, 2024

@Kahbazi @maartenba should we change that to WriteAsync

I think it's better to keep the async and add await before it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants