Closed rocgao closed 6 years ago
I have found out the bug. The DistributedCacheRateLimitCounterHanlder.Get method will be called, when the RedisCache is enabled. Within the method, call JsonConvert.DeserializeObject funtion to load RateLimitCounter instance from json string. But both Timestamp and TotalRequests properties are readonly of the RateLimitCounter struct. So to fix this bug, should apply the JsonConstructorAttribute to RateLimitCounter's constructor and rename totalRequest parameter to totalRequests.
[JsonConstructor]
public RateLimitCounter(DateTime timestamp, long totalRequests)
{
Timestamp = timestamp;
TotalRequests = totalRequests;
}
@rocgao thanks for this issue and the fix. I really appreciate it. I will merge this into NuGet package ASAP.
fixed in 11.0.3, any problems let me know
@rocgao add me with wechat geffzhang
@rocgao @geffzhang Are you still with Ocelot?
Regarding the user scenario with RedisCache... How did/does this setup work in Production env? Are you satisfied? Can we develop this setup of services to a real Ocelot feature? We could develop at least new Ocelot DI-extension method for the first time.
Expected Behavior
External http request should be blocked when quota exceeded.
Actual Behavior
External http request was forwarded to downstream servers always.
Steps to Reproduce the Problem
Enabling DistributedCache. Refer to following code:
Specifications