.NET project hosted on IIS is timing out in 5 minutes but works fine on localhost

56 Views Asked by At

We are working on a .NET WCF project where we have hosted our different services on IIS. One of our post methods is currently taking more than 10 minutes to get a response from an external server. The project runs and works fine from localhost, but on IIS its timing out in 5 minutes and gives us a 500 Internal Server error. My question is what approach should we take to resolve this error, and how can we log the exact error that is being thrown.

We have tried changing the IIS settings using IIS Manager, adding execution timeout within the Web.config file, setting the HttpWebRequest timeout to over 10 minutes.

1

There are 1 best solutions below

0
Carson T On

If I understand your question correctly, you are trying to identify why the response takes so long to come back, not just trying to increase the timeout to compensate. If your expectation is to have an http call that takes minutes to respond, then I agree with Lex Li that you have a fundamental design problem. I'm going to assume you're trying to determine the cause of the slowdown for the rest of my answer.

Issues like these can often be caused by thread deadlock. If you're mixing synchronous and asynchronous contexts, I would start my investigation there. In particular any use of .Result or .Wait() should be analyzed. Consider using .ConfigureAwait(false) in these scenarios, as this can often resolve the issue. See this post for more info: Usage of ConfigureAwait in .NET

As for logging, there are lots of 3rd party logging frameworks out there, any of them will suffice for your debugging needs in this scenario. I'm particularly fond of Azure Application Insights (if you're using Azure), Splunk, and SumoLogic.