softwerkab / fortnox-csharp-api-sdk

.NET SDK for Fortnox API.
MIT License
52 stars 64 forks source link

Rate limiter issue #149

Closed PatrikFomin closed 3 years ago

PatrikFomin commented 3 years ago

It seems that each time I hit the rate limiter, IIS hangs for new requests. Is there anything in the rate limiter that blocks the thread from resuming once the time is up? (I haven't had the chance to look into it.)

I am unsure how to best reproduce it. What I am doing is first calling get invoices with the customer number then subsequently get all invoices for that customer (which can often be more than 4).

var invoiceConnector = GetInvoiceConnector();
var searchCriteria = new InvoiceSearch
    {
        CustomerNumber = customerNumber
};
var invoices = invoiceConnector.Find(searchCriteria);

Loop over invoices.Entities and get each invoice individually. var invoice = invoiceConnector.Get(long.Parse(invoiceNumber));

Hangs every other attempt if it's more than 4 invoices and never resumes (it seems). When I turn off the rate limiter and let the server use my burst, then it seems to work.

richardrandak commented 3 years ago

Hi Patrik! There might be something wrong, since similar behaviour was reported in #147 Can you try with NuGet 4.0.7-preview ? I have added a ConfigureAwait(false) after calling the rate limiter.

PatrikFomin commented 3 years ago

Hi Patrik! There might be something wrong, since similar behaviour was reported in #147 Can you try with NuGet 4.0.7-preview ? I have added a ConfigureAwait(false) after calling the rate limiter.

Hi Richard,

Same problem in 4.0.7-preview. If I have the rate limiter enabled it hangs IIS, if I deactivate it it works.

I am creating a new FortnoxClient for every web request (scoped) and not transient or singleton. (In case that can effect anything)

richardrandak commented 3 years ago

Unfortunately, I am not able to reproduce it, even by using ASP WEB API project. Is it happening to you when you run it from VisualStudio? Could you please send me your project with the bare minimum required to reproduce it? I could then try investigating the issue and hopefully solve it. You can send it to my mail address richard.randak@softwerk.se Naturally, remove your credentials. I will use mine.