BaghDad wrote:
I have had this exact issue for months as I've developed my staging site, and it's the last problem I need to address before moving to production.  Essentially the Schedule Tasks run correctly for several hours but then the app shuts down anyway at random times.

Seems closely related to:
https://github.com/dotnet/aspnetcore/issues/19509

and it's predecessor that has been opened/closed many times:
https://1stkissmanga.online/manga/cherry-blossoms-after-winterr/

more:
https://github.com/dotnet/AspNetCore.Docs/issues/12232

More or less stating that Kestrel fails to restart after a recycle.  I have read every thread for "Schedule Tasks Not Working", however mine do work for a time and the issue feels like it should be an application pool / IIS configuration or setting that I'm missing.

I have App Pool Settings:
Start Mode: Always Running
Idle Timeout: 0
Regular Time Interval: 0

I have also tried :
serverAutoStart="true" on the site
preloadEnabled="true" on the application

Tail of the log below showing the app shutting down after Schedule Tasks run.  I believe the POST to localhost should be the IIS sentry for preload/warmup.  I have HTTPS enforced and have tried this URL Rewrite with no effect on startup:
https://docs.microsoft.com/en-ca/troubleshoot/aspnet/application-fail-ssl-web


info: System.Net.Http.HttpClient.default.LogicalHandler[100]
      Start processing HTTP request POST https://nopstaging.af1racing.com/scheduletask/runtask
info: System.Net.Http.HttpClient.default.ClientHandler[100]
      Sending HTTP request POST https://nopstaging.af1racing.com/scheduletask/runtask
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 POST http://nopstaging.af1racing.com/scheduletask/runtask application/x-www-form-urlencoded 69
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 2.2.4-servicing-10062 initialized 'NopObjectContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MaxPoolSize=128 using lazy-loading proxies
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@__systemName_0='?' (Size = 400)], CommandType='Text', CommandTimeout='30']
      SELECT TOP(1) [c].[Id], [c].[Active], [c].[AdminComment], [c].[AffiliateId], [c].[BillingAddress_Id], [c].[CannotLoginUntilDateUtc], [c].[CreatedOnUtc], [c].[CustomerGuid], [c].[Deleted], [c].[Email], [c].[EmailToRevalidate], [c].[FailedLoginAttempts], [c].[HasShoppingCartItems], [c].[IsSystemAccount], [c].[IsTaxExempt], [c].[LastActivityDateUtc], [c].[LastIpAddress], [c].[LastLoginDateUtc], [c].[RegisteredInStoreId], [c].[RequireReLogin], [c].[ShippingAddress_Id], [c].[SystemName], [c].[Username], [c].[VendorId]
      FROM [Customer] AS [c]
      WHERE [c].[SystemName] = @__systemName_0
      ORDER BY [c].[Id]
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@__entityId_0='?' (DbType = Int32), @__keyGroup_1='?' (Size = 400)], CommandType='Text', CommandTimeout='30']
      SELECT [ga].[Id], [ga].[EntityId], [ga].[Key], [ga].[KeyGroup], [ga].[StoreId], [ga].[Value]
      FROM [GenericAttribute] AS [ga]
      WHERE ([ga].[EntityId] = @__entityId_0) AND ([ga].[KeyGroup] = @__keyGroup_1)
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
      Route matched with {action = "RunTask", controller = "ScheduleTask", area = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult RunTask(System.String) on controller Nop.Web.Controllers.ScheduleTaskController (Nop.Web).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method Nop.Web.Controllers.ScheduleTaskController.RunTask (Nop.Web) - Validation state: Valid
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@__type_0='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
      SELECT TOP(1) [st].[Id], [st].[Enabled], [st].[LastEndUtc], [st].[LastStartUtc], [st].[LastSuccessUtc], [st].[Name], [st].[Seconds], [st].[StopOnError], [st].[Type]
      FROM [ScheduleTask] AS [st]
      WHERE [st].[Type] = @__type_0
      ORDER BY [st].[Id] DESC
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@p8='?' (DbType = Int32), @p0='?' (DbType = Boolean), @p1='?' (DbType = DateTime2), @p2='?' (DbType = DateTime2), @p3='?' (DbType = DateTime2), @p4='?' (Size = 4000), @p5='?' (DbType = Int32), @p6='?' (DbType = Boolean), @p7='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
      SET NOCOUNT ON;
      UPDATE [ScheduleTask] SET [Enabled] = @p0, [LastEndUtc] = @p1, [LastStartUtc] = @p2, [LastSuccessUtc] = @p3, [Name] = @p4, [Seconds] = @p5, [StopOnError] = @p6, [Type] = @p7
      WHERE [Id] = @p8;
      SELECT @@ROWCOUNT;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@__nowUtc_0='?' (DbType = DateTime2), @__maxSendTries_1='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
      SELECT COUNT(*)
      FROM [QueuedEmail] AS [qe]
      WHERE ([qe].[SentOnUtc] IS NULL AND ([qe].[DontSendBeforeDateUtc] IS NULL OR ([qe].[DontSendBeforeDateUtc] <= @__nowUtc_0))) AND ([qe].[SentTries] < @__maxSendTries_1)
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@__nowUtc_0='?' (DbType = DateTime2), @__maxSendTries_1='?' (DbType = Int32), @__p_2='?' (DbType = Int32), @__p_3='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
      SELECT [qe].[Id], [qe].[AttachedDownloadId], [qe].[AttachmentFileName], [qe].[AttachmentFilePath], [qe].[Bcc], [qe].[Body], [qe].[CC], [qe].[CreatedOnUtc], [qe].[DontSendBeforeDateUtc], [qe].[EmailAccountId], [qe].[From], [qe].[FromName], [qe].[PriorityId], [qe].[ReplyTo], [qe].[ReplyToName], [qe].[SentOnUtc], [qe].[SentTries], [qe].[Subject], [qe].[To], [qe].[ToName]
      FROM [QueuedEmail] AS [qe]
      WHERE ([qe].[SentOnUtc] IS NULL AND ([qe].[DontSendBeforeDateUtc] IS NULL OR ([qe].[DontSendBeforeDateUtc] <= @__nowUtc_0))) AND ([qe].[SentTries] < @__maxSendTries_1)
      ORDER BY [qe].[PriorityId] DESC, [qe].[CreatedOnUtc]
      OFFSET @__p_2 ROWS FETCH NEXT @__p_3 ROWS ONLY
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[@p8='?' (DbType = Int32), @p0='?' (DbType = Boolean), @p1='?' (DbType = DateTime2), @p2='?' (DbType = DateTime2), @p3='?' (DbType = DateTime2), @p4='?' (Size = 4000), @p5='?' (DbType = Int32), @p6='?' (DbType = Boolean), @p7='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
      SET NOCOUNT ON;
      UPDATE [ScheduleTask] SET [Enabled] = @p0, [LastEndUtc] = @p1, [LastStartUtc] = @p2, [LastSuccessUtc] = @p3, [Name] = @p4, [Seconds] = @p5, [StopOnError] = @p6, [Type] = @p7
      WHERE [Id] = @p8;
      SELECT @@ROWCOUNT;
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action method Nop.Web.Controllers.ScheduleTaskController.RunTask (Nop.Web), returned result Microsoft.AspNetCore.Mvc.NoContentResult in 3.343ms.
info: Microsoft.AspNetCore.Mvc.StatusCodeResult[1]
      Executing HttpStatusCodeResult, setting HTTP status code 204
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action Nop.Web.Controllers.ScheduleTaskController.RunTask (Nop.Web) in 4.0942ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 7.4895ms 204
info: System.Net.Http.HttpClient.default.ClientHandler[101]
      Received HTTP response after 11.9196ms - NoContent
info: System.Net.Http.HttpClient.default.LogicalHandler[101]
      End processing HTTP request after 11.9848ms - NoContent
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 POST http://127.0.0.1:39214/iisintegration  0
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 0.0519ms 202
Application is shutting down...


hey its stops automatically unexpectedly many times, got errors in log file


I have had this exact issue for months as I've developed my staging site, and it's the last problem I need to address before moving to production.  Essentially the Schedule Tasks run correctly for several hours but then the app shuts down anyway at random times.