5

Technologies

I am using angular 2 and web API technologies in my application. I am calling web API service method from angular via $http call.

What I am doing

Actually API method is reading data from data base and doing huge logic to transform the data for UI entity class (lot of codes and loops are there, so i won't post those here).

What is the problem & root cause

The problem is I am getting 502 Bad get way error when I am calling the API method.

I found the problem because of it's a performance issue. it's working fine for me when the data size is low. But if the data size is large, then I am getting this error.

Note : I have checked the data base query. and it's working fine and return the data very fast.

Performance result details

I have used timer to check the response time of API method

Result of response time as follow :

  • if the data size is low : 00.00:898767 (hh:mm:ss)

  • if the data size is huge : 00:06:654389 (hh:mm:ss)

What I understood:

If the method response time is more than 2 mins, then only I am getting the bad get way error. otherwise the method executed successfully without any error.

What I tried to fix this error:

I have tried to increase the executionTimeout=9000 in web config. I also tried with different seconds in executionTimeout.

this is my full web config code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--
    Configure your application  settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->
  <system.web>
    <authentication mode="Windows"></authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <httpRuntime  executionTimeout = "9000" />
  </system.web>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true" />
  </system.webServer>
</configuration>

but still i am unable to solve this problem. Could you please let me know how can I fix this issue?

Community
  • 1
  • 1
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • 2
    You may be hitting request size limits in Kestrel and/or IIS with large payloads, which are being rejected before user code is reached. For example I had a similar issue in .NET Core where I was getting errors with certain payloads which only replicated when hitting the application when running in IIS (so not Kestrel with local testing). The reason turned out to be that an 3rd party application was generating long query strings as part of OAuth flow. The fix in that case was to raise the max query string length in IIS using ``. – Martin Costello Aug 17 '18 at 11:55
  • Also try to set the following values if it is caused by request length issue: Sometimes both should be set. Bear in mind that maxAllowedContentLength need three more zeros. – user890255 Aug 17 '18 at 12:03
  • I have tried those above comments. But still I am not able to rsolve it. – Ramesh Rajendran Aug 20 '18 at 06:29

1 Answers1

4

I solved this defect by adding requestTimeout="00:10:00" in <aspNetCore/> section

<aspNetCore processPath="%LAUNCHER_PATH%"  requestTimeout="00:10:00" 
arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" 
forwardWindowsAuthToken="true" />
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • Thanks. It helped me. But when around 4th minute, I get Access to XMLHttpRequest at 'https://<>' from origin 'https://<>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Any idea ? When there is less data, no error and it works as expected. The CORS occurs only when huge data is processed. – Gopi Mar 12 '20 at 15:09
  • This could because of other missing CORS headers. Access-Control-Allow-Headers, Access-Control-Allow-Methods. Refer https://stackoverflow.com/questions/6516591/how-to-implement-access-control-allow-origin-header-in-asp-net. – Satheesh K Apr 28 '22 at 15:47