ASP.Net request raises 502 Bad Gateway or TimeOut
Asked Answered
P

2

6

I have a C# ASP.NET Webforms website running on IIS7. It is a report creation application that queries the SQL Server database, gets the data, parses it in to an Excel document.

The query itself doesn't take too long, but writing to the Excel takes a while when the query is very large (50,000 rows).

Now for the problem, when I run the report app, I get the report with in a few minutes but when some users run it, the report returns 502 Bad Gateway. This only happens for large reports.

I assume that it has to do with a timeout? Even though no matter which timeout command I change, the gateway error comes up with in two minutes.

Prior answered 2/8, 2013 at 16:12 Comment(2)
Can you get the substatus of the 502 errors (from the IIS logs)? Also, not sure how you're doing it but have a look at the following question (linked below) to see how to write to Excel ranges quickly. Using the interop methods is devastatingly slow. If you are, then maybe changing to this strategy will help you solve your problem. https://mcmap.net/q/48583/-write-array-to-excel-rangeAndreasandree
I think this problem is still exists and AFAIK, it's not related to timeout, it is related to the service that prepares the response, and raises 502 error when it's in a situation of down!, And by restarting that service you will not see that error (A temporarily solution), but it is not the correct solution, HTH ;).Slipper
I
7

I have the same error 502 on ASP.NET Core, while build large reports. My issue is not in out of memory. Logs show me that the process is not interrupted while i've got the error 502, and it continue builds reports til the end. The reason of the error is timeout from IIS. If i set "requestTimeout" like:

<aspNetCore requestTimeout="00:20:00" processPath=".\xxx.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
</aspNetCore>

in web.config, so for local URL (with localhost) - the error 502 will disappear and i'll get all reports, even huge, but for external URL (with domain names) timeout still the same - 120 sec, and 502 error. RequestTimeout in web.config and the next settings completely resolve my problem: In the Internet Information Services dialog box, expand local computer > Sites and right click Default Website and select Manage Web Site > Advance Settings. Expand Connection Limits, change the Time-out value to XXXX, and click OK.

Update: Also there is the third additional option where should be increased limit. In the IIS select your site. On the bottom panel open Configuration Editor. In the top of Editor choose system.web/httpRuntime. Find option "executionTimeout" and set new value.

Incubate answered 12/12, 2019 at 9:24 Comment(0)
P
1

The issue had to do with memory and we had to change the architecture. Since then, we have moved to dedicated report servers and split the reports into different parts (i.e different time frames) and combined them again once each report is done. This can easily be achieved via Azure Queue and Blob Storage. The reports are also emailed instead of returned back in an HTTP call.

Prior answered 23/7, 2019 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.