ikyriak / IdempotentAPI

A .NET library that handles the HTTP write operations (POST and PATCH) that can affect only once for the given request data and idempotency-key by using an ASP.NET Core attribute (filter).
MIT License
283 stars 40 forks source link

Get 409 status code when retry #37

Closed khoavn closed 2 years ago

khoavn commented 2 years ago

I have 2 services, A and B and A calls B to create objects, and I use Polly to retry requests sent by A. The problem is when B crashed why processing request from A then Polly retries with same IdempotencyKey and it get 409 response instead re-run action method of B. Should we capture request/response only when request completed successfully? What should I do in this case?

ikyriak commented 2 years ago

Hello @khoavn ,

Thanks for taking the time to report this issue!

I have confirmed the following two cases in which the IdempotentAPI didn't respond as expected. For that reason, I made some corrections and improvements.

However, as long as a request is in the inflight mode (running), all other requests will still get a 409 Conflict response. For that reason, we should be careful when configuring the request timeout.

Could you please try the 1.0.2-prerelease-01 versions of the IdempotentAPI library and set the CacheOnlySuccessResponses attribute option to true, for example:


[Idempotent(CacheOnlySuccessResponses = true)]
public class WeatherForecastController : ControllerBase
{
    // ...
}
khoavn commented 2 years ago

Hi @ikyriak, Apologies for the delayed response. After upgrading I get this message: Unhandled exception. System.TypeLoadException: Method 'Remove' in type 'IdempotentAPI.Cache.FusionCache.IdempotencyFusionCache' from assembly 'IdempotentAPI.Cache.FusionCache, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. when call AddIdempotentAPIUsingFusionCache method.

ikyriak commented 2 years ago

Hello @khoavn,

Oops! Sorry, I didn't publish the 1.0.2-prerelease-01 version of the IdempotentAPI.Cache.FusionCache library 😄. You can find all the pre-release versions here. Can you please try to update all the IdempotentAPI libraries that you use to 1.0.2-prerelease-01?

khoavn commented 2 years ago

Thank you, it works now, but could we default CacheOnlySuccessResponses to true? I can't find cases where caching Controller crash useful.

ikyriak commented 2 years ago

Hello @khoavn,

We have set the default value of CacheOnlySuccessResponses to true in the v2.0.0-RC.01 release 🎆🎉. Thank you again for reporting this issue 🙏.