9

I'm hosting an ASPNET Core 1.1 app on IIS with the following settings to keep it always running

enter image description here

However, I see the app getting terminated time to time. Before termination I see the following in the logs

2018-03-14 17:20:53.202 [Information] Request starting HTTP/1.1 POST http://127.0.0.1:32751/myapp/iisintegration  0
2018-03-14 17:20:53.205 [Information] Request finished in 3.98ms 202 
2018-03-14 17:20:53.203 [Error] Unhandled exception
System.Threading.Tasks.TaskCanceledException: A task was canceled.

The POST /iisintegration looks interesting. Is IIS sending a command to terminate the app?

P.S.

After digging around IIS integration middleware, it looks like that POST is actually IIS sending a termination command. This is the code that handles it

private static readonly PathString ANCMRequestPath = new PathString("/iisintegration");
...
    // Handle shutdown from ANCM
if (HttpMethods.IsPost(httpContext.Request.Method) &&
    httpContext.Request.Path.Equals(ANCMRequestPath) &&
    string.Equals(ANCMShutdownEventHeaderValue, httpContext.Request.Headers[MSAspNetCoreEvent], StringComparison.OrdinalIgnoreCase))
{
    // Execute shutdown task on background thread without waiting for completion
    var shutdownTask = Task.Run(() => _applicationLifetime.StopApplication());
    httpContext.Response.StatusCode = StatusCodes.Status202Accepted;
    return;
}

So my question is: Is there a way to disable this functionality?

ubi
  • 4,041
  • 3
  • 33
  • 50
  • Just remove the complete IF block could help?! Or comment the line `var shutdownTask ...` if the rest of the block is important for something. – Alex Mar 16 '18 at 02:54
  • Lol.. if aspnet team allows me to do that just to fix my issue ;) – ubi Mar 16 '18 at 03:25
  • Does your app run without IIS integration? – Brad Mar 16 '18 at 04:26
  • Do you have a file called "app_offline.html" in your root directory? https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module#appofflinehtm Maybe that is causing the shutdown? – Simply Ged Mar 16 '18 at 09:04
  • Unhandled exceptions from a thread can terminate the whole process. – Lex Li Mar 17 '18 at 00:56
  • @Brad yes it runs without IIS integration. The termination is initiated by IIS. I'm trying to find a way to disable it – ubi Mar 18 '18 at 23:53
  • @ubi were you lucky with this matter? I have the same problem – svillamayor Jun 06 '18 at 12:40
  • No luck so far, what I ended up doing was to create a shell script to ping the application periodically. yuck, I know. There's another option which I haven't tried which is setting the Recycling time interval in application pool to 0. – ubi Jun 06 '18 at 23:29

1 Answers1

3

Try to remove your Recycling Conditions from your application pool

Mossila
  • 169
  • 2
  • 9