1

I am working on a .NET Core 3.1 web api application and am having a terrible time with something closing my long running API request.

I have a POST endpoint that looks like this (slightly simplified):

       [HttpPost]
       [IgnoreAntiforgeryToken]
       [ActionName("LoadDataIntoCache")]
       public async Task<IActionResult> LoadDataIntoCache([FromQuery] string filter)
       {
           //long running process (15-20 mins)
           var success = await _riskService.LoadDataIntoCache(filter);
           if (success == false)
           {
               return StatusCode(StatusCodes.Status500InternalServerError);
           }
           return Ok();
       }

This endpoint works fine when I test it locally via Postman. However, when I push this to the server (IIS), and hit the endpoint via Postman it produces an error after 5 minutes: Error: read ECONNRESE.

No more details are produced that this. Checking the logs of the application, it does not throw an exception, in fact it appears that the long running processes continues to run as if nothing is wrong. Its as if the connection itself is just being closed by something, but that the application is working fine.

I have also tried calling this endpoint via C# instead of Postman. My calling code produced the following exception message Processing of the HTTP request resulted in an exception. and additionally The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

I have checked the IIS timeout, which is set to 120s, which does not align with the 5 minute time I am seeing. I have checked a bunch of timeout settings on the .NET side, but my understanding is the .NET Core 3.1 does not need this settings because it will wait forever by default? This application is also set to run inProcess if that is significant...

I am really scratching my head on this one. Any pointers would be much appreciated.

Tanner.R
  • 479
  • 1
  • 6
  • 15
  • Have you considered not having the request take so long? e.g. add entry to a queue to process, and then a second endpoint to poll for progress? – mjwills Jan 08 '21 at 23:56
  • Maybe this can point you in the right direction. https://stackoverflow.com/a/6230929/9936356. I personally wouldn't have a task running for ~5mins. Why not create a background service to handle this and take this off your application? Esp for an api, why make the user wait 5-10mins for a single request? – LinkedListT Jan 09 '21 at 00:07
  • @LinkedListTI will definitely take a look at this. This is a nightly data load, so no actual users will be waiting on this endpoint, just need it to continue through the process of pulling in data to some of our systems. – Tanner.R Jan 09 '21 at 00:12
  • `just need it to continue through the process of pulling in data to some of our systems.` Given IIS can restart, this is a reason why you _shouldn't_ do this in the web tier. Stick it in a queue, and process it in a separate application. – mjwills Jan 09 '21 at 00:15

0 Answers0