Skip to content

reopen issue #10117 - IIS app pool recycle throws 503 errors #41340

Closed

Description

@alex-jitbit

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

IIS app pool throws 503 errors during recycles. This is a known issue with ANCM module that has been reported previously in #10117 - which has 33 likes and a 3-year discussion, it was never fixed, but it was automatically closed by a bot "as a clean-up due to lack of discussion".

P.S. This is not a deployment problem. There are many scenarios when IIS app pool is being recycled outside of our control (adding/removing SSL certificates, changing IP addresses to listen to, etc... basically, touching any IIS setting causes a recycle - and 503 errors are unacceptable for high-availability scenarios).

.NET Framework was free of this bug.

Expected Behavior

No errors during recycles.

Steps To Reproduce

see the issue linked #10117

Exceptions (if any)

No response

.NET Version

5.0, 6.0 7.0 8.0

Anything else?

No response

Activity

  1. Tratcher commented on Apr 25, 2022

    @Tratcher
    Member

    #10117 (comment)

    Using separate app pools and a load balancer is our recommended approach for high-availability as it allows you full flexibility over deployment process and the ability to easily revert versions.

    Trying to achieve high-availability with a single instance is not recommended.

  2. alex-jitbit commented on Apr 25, 2022

    @alex-jitbit
    ContributorAuthor

    @Tratcher like I indicated above, this is not about deployments. There are a lot of scenarios when IIS recycles the pool (see above)

  3. Tratcher commented on Apr 25, 2022

    @Tratcher
    Member

    Deployments are just one example that disrupt availability. A single instance is not advised for high-availability for many reasons.

  4. added this to the Backlog milestone on Apr 25, 2022
  5. benjamin-stern commented on Apr 26, 2022

    @benjamin-stern

    @Tratcher Even having more than a single instance this would still strongly affect a service, as all the requests going to the server that's recycling would be returned the 503 error.

  6. c0shea commented on Apr 26, 2022

    @c0shea

    We have two instances running behind a load balancer and have still experienced this issue intermittently. When the app pool inevitably recycles (due to deployment, config change, etc), it starts returning 503 instead of queuing up the requests.

    The load balancer doesn't immediately treat the 503s as the server being down and take it out of the rotation. Instead, it uses a polling mechanism that calls an endpoint (i.e. /status) on each instance and checks for a successful response. While that status endpoint is monitored frequently enough, there is obviously plenty of time where a bunch of requests will fail with 503 while the recycle is happening. We can't have the load balancer take the instance out of the rotation if it sees 503s being returned because (1) it's not an available option in NetScaler and (2) if both happen to recycle at the same time, both servers would be taken out of the rotation and the service would be completely down until manual intervention told the load balancer that the requests aren't failing anymore.

  7. RomBrz commented on Apr 26, 2022

    @RomBrz

    In this scenario (using two or more instances behind a load balancer), since you're using a "/status" to check availability, i suggest that you make some routines during the deployment or maitenence to, before start doing anything, force the "/status" to throw an "unhealthy" status, so the load balance could remove the node from the balancer and then make the changes.

    About the issue itself, the IIS default behavior on a recycle is to first start a new application pool, route the new requests to the new application pool, wait the default set time to the current requests ends, an than close/finish the current application pool, keeping only the new as the application pool.

    Recycling an application pool, could be an ASPNET Core "expected behavior", but looking at IIS, throwing 503 during one recycle isn't a "normal behavior".

  8. c0shea commented on Apr 26, 2022

    @c0shea

    The problem is that ASP.NET Core doesn't use the overlapping recycle behavior that .NET Framework did. While the old worker process is being shutdown (especially if there were a lot of inflight requests being handled by it), the new process isn't yet started and those requests in the middle get the 503.

  9. alex-jitbit commented on Jun 18, 2022

    @alex-jitbit
    ContributorAuthor

    TIL that StackOverflow also runs ASP.NET Core under IIS

    image

  10. luizfbicalho commented on Jul 5, 2022

    @luizfbicalho

    Is there any way to minimize this problem, or ate least to detect what is causing it?
    Any configuration in the application pool to minimize it?

  11. peter-bertok commented on Sep 20, 2022

    @peter-bertok

    Deployments are just one example that disrupt availability. A single instance is not advised for high-availability for many reasons.

    High availability and throwing 503s from otherwise "perfectly fine servers" are separate concerns.

    Most load balancers do not hide HTTP errors! If the IIS process responds to a HTTP request with 503, then that's what the user will see. In particular, none of the Azure load balancer offerings hide errors from the users. They pass them on faithfully.

    If a previously working server throws 503 errors then it will take significant time for the load balancers to detect this. Minutes even, or 10+ minutes if using CDN-type solutions such as Azure Front Door.

    This behavior is triggered by many actions, not all of which are resolved via hosting on multiple server instances. Scheduled recycling, for example, has been mentioned by many people as a common trigger.

    Similarly, many people have pointed out in the previous thread that it's not just 503 errors that are seen, but slow uploads are also unceremoniously terminated.

  12. luizfbicalho commented on Sep 20, 2022

    @luizfbicalho

    My problem seems to be on IIS recycle when takes too long to recycle, it's not related to cpu neither to memory, I asked the IT infrastructure to add more performance counters to grafana but they didn't add yet,

    I'm inclined to think that the problem is with Network connections, what do you think that I should monitor in grafana?

  13. 68 remaining items

  14. bluntspoon commented on Apr 17, 2024

    @bluntspoon

    Thanks for starting the PR for this issue @BrennanConroy. Keen to know which versions of DotNet will get this fix once merged. Seeing updates to dotnet6+ would be awesome.

  15. BrennanConroy commented on Apr 22, 2024

    @BrennanConroy
    Member

    This will be opt-out in 9.0 and we're backporting as opt-in for 8.0. Since the change is in the IIS module which is installed globally on the machine and the module is compatible with all supported versions of ASP.NET Core you can use the 8.0 or 9.0 module with 6.0 and still get the fix.

    When installing the hosting bundle (which is what installs the IIS module) you can choose to ignore the runtime that comes with the installer if you want to continue using 6.0 but get the newer module. See https://learn.microsoft.com/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-8.0#options for details.

  16. RomBrz commented on Apr 23, 2024

    @RomBrz

    Great to see this problem being solved! As the Hosting Bundle packages, some time ago i tried that "choice to ignore the runtime" but for some reason "Install Hosting Bundle with runtimes and after that uninstall both runtimes" gave me a different setup than "Install Hosting Bundle only without runtime". Even the size of the Hosting Bundle was different. Seems to persist this "bug":
    (After Install with OPT_NO_RUNTIME=1)
    image

    (After Full Install)
    image

    On our servers all the DotNet core apps only works with the 145MB Server Hosting (so i have to do a full install and after that remove the runtimes).

    Considering that you are working with ANCM, some time ago i posted about this problem involving IIS, DotNet Core and Windows Update (#41377). The problem persists as for some reason i need to put IIS in manual mode, reboot server, than do the Windows Update full install (Windows security patches, Dotnet Framework security patches and DotNet Core patches).

  17. MV10 commented on Apr 30, 2024

    @MV10

    A little bit off-topic, but until we have this fix deployed, our monitoring is being configured to ignore Failed to gracefully shut down application XYZ error messages (which correlate to the recycle 503s, of which there are many since corporate policy still requires early-AM staggered-schedule recycles of all pools).

    Is there a reference somewhere of the various warnings and errors ANCM can emit?

  18. simon-biber commented on May 15, 2024

    @simon-biber

    Did this fix get into .NET 8.0.5 hosting bundle?

  19. MV10 commented on May 15, 2024

    @MV10

    The way I read it, it'll be released with .NET 9 in November, and backported to .NET 8.x.x at that time...

  20. cun-dp commented on May 15, 2024

    @cun-dp

    According to milestone tags the fix ist slated for the next release 8.0.6: https://github.com/dotnet/aspnetcore/issues?q=milestone%3A8.0.6%20is%3Aclosed%20label%3Aservicing-approved

    🤞

  21. adityamandaleeka commented on May 15, 2024

    @adityamandaleeka
    Member

    @cun-dp is right, it'll ship in the 8.0.6 release in June.

  22. BrennanConroy commented on May 21, 2024

    @BrennanConroy
    Member

    This fix is out in 9.0-preview4 now. And will be available in 8.0.7 in July-2024.

    I'm going to close and lock this issue so that this comment, which will include detailed instructions below, is the last one. For those of you who have been posting semi-unrelated issues, please file separate issues for them.

    Instructions

    When installing the hosting bundle (which is what installs the global IIS module) you can choose to ignore the runtime that comes with the installer if you want to continue using an older runtime but get the newer modules improvements. See https://learn.microsoft.com/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-8.0#options for details. Otherwise, install the hosting bundle as normal to get the IIS module installed.

    There are 2 ways to modify the behavior of this change.

    1. Modify the shutdownDelay option in your web.config handlerSettings.
    <aspNetCore processPath="dotnet" arguments="myapp.dll" stdoutLogEnabled="false" stdoutLogFile=".logsstdout">
      <handlerSettings>
        <!--
        Milliseconds to delay shutdown of the old app app instance while the new instance starts.
        Note: This doesn't delay the handling of incoming requests.
        -->
        <handlerSetting name="shutdownDelay" value="5000" />
      </handlerSettings>
    </aspNetCore>
    1. Set the ANCM_shutdownDelay environment variable, also in milliseconds.

    If you set the value to 0, then it goes back to the old behavior.

    For 9.0 >=, the fix is on by default and can be disabled by setting the config to 0.

    For >= 8.0.7, the fix is off by default and can be enabled by setting the config to a value > 0.

    The default is 1000 milliseconds (1 second). For busy/slow machines you may want to increase this value.

  23. locked as resolved and limited conversation to collaborators on May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-networkingfeature-iis

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions