3

I am inserting about 50k rows into a database using a PowerShell script and a .NET Core app (App 1 (PowerShell) is sending the data to App 2 (.NET Core), which id inserting the data).

I am using Entity Framework and I've implemented a mechanism in App 2 for faster inserting, something along the lines of this: Fastest Way of Inserting in Entity Framework

What happens is the inserting takes a little while, but it finishes fine with all the data being inserted correctly into the database. The query runs for about 4 minutes.

However, App 1 gets back a generic "HTTP Error 502.3 - Bad Gateway". This response gets returned even before all the data has been inserted into the database. So App 2 just sends back an error, but the db operations continue as if nothing happened.

So the problem is, the db inserts are working properly, but I have no way of knowing that in App 1, since all I get is a generic error every time.

I've tried increasing IIS timeouts, sessions timeouts in both apps, reading IIS logs and NET Core generated application logs. No success.

How do I make App 2 wait until the query is finished to get a proper response?

.NET Core version is 1.0.0-preview2-003121

Powershell request :

$post = Invoke-WebRequest -Uri ([string]$ApiUrl+$moduleApi) -Method Post -ContentType "application/json; charset=utf-8" -Body $json -Headers @{'ClientID' = "$clientID"; "Authorization"="Bearer $encryption"} -ErrorVariable errorMsg -UseBasicParsing -TimeoutSec 600
Community
  • 1
  • 1
faso
  • 679
  • 7
  • 25
  • 3
    https://learn.microsoft.com/en-us/aspnet/core/hosting/aspnet-core-module *requestTimeout ... The default value is "00:02:00".* Have you increased this? – ta.speot.is Mar 13 '17 at 10:20
  • With a 4 minutes running web request, a progress indicator might be appropriate, but ta.speot.is pointed out the most important thing I guess. – grek40 Mar 13 '17 at 10:22
  • IIS `executionTimeout` is "how long will IIS process the request before deciding something is wrong". But `requestTimeout` is "how long will the client wait before deciding something is wrong". Each decision is made independently (because they are running on different computers). – Ben Mar 13 '17 at 10:35
  • 1
    @Ben `requestTimeout` is *the duration for which the ASP.NET Core Module will wait for a response*. `executionTimeout` still might be relevant because IIS/ASP.NET Module and the process that hosts the application are *different processes*. But both run on the server. Separately, OP already shows he's configuring the client timeout: `-TimeoutSec 600`. – ta.speot.is Mar 13 '17 at 10:42

2 Answers2

5

Increase requestTimeout to something that exceeds four minutes.

ASP.NET Core Module configuration reference

requestTimeout

Optional timespan attribute.

Specifies the duration for which the ASP.NET Core Module will wait for a response from the process listening on %ASPNETCORE_PORT%.

The default value is "00:02:00".

Community
  • 1
  • 1
ta.speot.is
  • 26,914
  • 8
  • 68
  • 96
1

Set the requestTimeout to 0 - This means it will essentially wait indefinitely until the Database is done. The client just doesn't want to wait for the DB to finish, but the DB continues even after throwing the error.

Aman
  • 133
  • 1
  • 9