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

The operation was canceled #126

Closed
EminemJK opened this issue May 21, 2020 · 5 comments
Closed

The operation was canceled #126

EminemJK opened this issue May 21, 2020 · 5 comments

Comments

@EminemJK
Copy link

EminemJK commented May 21, 2020

Hi, I found this problem in a production environment,

2020-05-21 02:51:42,900 [10] ERROR System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at Microsoft.Extensions.Caching.Redis.RedisCache.RefreshAsync(String key, Nullable`1 absExpr, Nullable`1 sldExpr, CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.GetAndRefreshAsync(String key, Boolean getData, CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.GetAsync(String key, CancellationToken token)
   at Microsoft.Extensions.Caching.Distributed.DistributedCacheExtensions.GetStringAsync(IDistributedCache cache, String key, CancellationToken token)
   at AspNetCoreRateLimit.DistributedCacheRateLimitStore`1.GetAsync(String id, CancellationToken cancellationToken)
   at AspNetCoreRateLimit.IpRateLimitProcessor.GetMatchingRulesAsync(ClientRequestIdentity identity, CancellationToken cancellationToken)
   at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at DigitalCertificateSystem.Handlers.ExceptionHandlerMiddleWare.Invoke(HttpContext context)

I use it in the same way as the documentation,
ConfigureServices:

services.AddDistributedRedisCache(options =>
                {
                    options.Configuration = config.Application.RedisConnection;
                    options.InstanceName = "DigitalCertificateSystem_WebRatelimit";
                });
                services.AddOptions();
                services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting"));
                services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>();
                services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>(); 
                services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();

Configure:

app.UseMiddleware<Application.Middleware.IPLimitMiddleware>();

public class IPLimitMiddleware : IpRateLimitMiddleware
    {
        public IPLimitMiddleware(RequestDelegate next, IOptions<IpRateLimitOptions> options, IRateLimitCounterStore counterStore, IIpPolicyStore policyStore, IRateLimitConfiguration config, ILogger<IpRateLimitMiddleware> logger)
            : base(next, options, counterStore, policyStore, config, logger)
        {
        }

        public override Task ReturnQuotaExceededResponse(HttpContext httpContext, RateLimitRule rule, string retryAfter)
        {
            httpContext.Response.Headers.Append("Access-Control-Allow-Origin", "*");
            return base.ReturnQuotaExceededResponse(httpContext, rule, retryAfter);
        }
    }

How should I solve it? I hope to get your help

@EminemJK
Copy link
Author

@cristipufu
Copy link
Collaborator

This doesn't seem to be related to the library itself, but to the underlying Redis library/connections

@EminemJK
Copy link
Author

This happens with high concurrency,and it affects access to other interfaces, and when I removed it, everything was fine.

@EminemJK
Copy link
Author

This doesn't seem to be related to the library itself, but to the underlying Redis library/connections

My question is the same as this one: #83 (comment)

@EminemJK
Copy link
Author

I've taken care of it myself.

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

2 participants