Skip to content

AspnetcoreModuleV2 shutdowns worker threads but not worker process, which results in 503 #66958

Closed

Description

@pledwon2

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hello

We have recently updated our applications from .NET 8 to .NET 10. We installed hosting bundle in version 10.0.8 on our CI servers. These servers run multiple applications targeting net48, net8 and net10.

We have noticed that applications running on dotnet core (net8 and net10) occasionally return 503 HTTP status codes. An applications started correctly and after some time it entered a state in which only 503 errors were returned.

This did not happen on hosting bundle in version 8.0.27.

Event logs showed that AspNetCoreModuleV2 logged that the application shut down correctly, but we could see that the worker process was still running, so we assumed that it is not being properly shut down.

Affected applications are running in separate application pools (1 app per pool) and are configured to recycle at 1:00 AM and after 20 minutes of inactivity, so these are not always running applications.

We searched through old github issues and found some changes in commit 42bc1a1 which we assumed could be related. We attempted to set shutdown delay to 0, which results in UseLegacyShutdown returning true (this is important for later).

When shutdown delay is 0, everything works correctly.

To try to find out what causes the issue, we enabled some additional logging in our affected applications and attempted to run them without setting shutdown delay to 0 (full log file is attached to the bug report). What can be seen in the log file is that we get OnGlobalApplicationStop and OnGlobalConfigurationChange, after which the shutdown is triggered. We assume that this is caused by changes to the IIS Server resulting from ongoing CI (new versions of applications are being installed and tested). Configuration change is irrelevant, as our applications are configured to not recycle on config changes, so what must be causing the application to shutdown is OnGlobalApplicationStop. This however, does not terminate the worker process and it enters the state of being shutdown, constantly returning 503 errors.

Here is the relevant fragment of the log:

...
[2026-06-01T13:08:59.790Z, PID: 13320] [aspnetcorev2_inprocess.dll] Removing Request 0
[2026-06-01T13:10:25.557Z, PID: 13320] [aspnetcorev2.dll] ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop
[2026-06-01T13:10:25.573Z, PID: 13320] [aspnetcorev2.dll] ASPNET_CORE_GLOBAL_MODULE::OnGlobalConfigurationChange 'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE'
[2026-06-01T13:10:25.582Z, PID: 13320] [aspnetcorev2.dll] Shutdown starting in 1000 ms.
[2026-06-01T13:10:25.916Z, PID: 13320] [aspnetcorev2.dll] ASPNET_CORE_GLOBAL_MODULE::OnGlobalConfigurationChange 'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE/1_0/OtherApp'
[2026-06-01T13:10:25.957Z, PID: 13320] [aspnetcorev2.dll] ASPNET_CORE_GLOBAL_MODULE::OnGlobalConfigurationChange 'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE/1_0/OtherApp'
[2026-06-01T13:10:26.601Z, PID: 13320] [aspnetcorev2.dll] Shutdown starting.
[2026-06-01T13:10:26.613Z, PID: 13320] [aspnetcorev2.dll] Stopping application '/LM/W3SVC/1/ROOT/1_0/MyApp'
[2026-06-01T13:10:26.618Z, PID: 13320] [aspnetcorev2_inprocess.dll] Stopping file watching.
[2026-06-01T13:10:26.642Z, PID: 13320] [aspnetcorev2_inprocess.dll] Waiting for file watcher thread to exit.
[2026-06-01T13:10:26.659Z, PID: 13320] [aspnetcorev2_inprocess.dll] Stopping file watcher thread
[2026-06-01T13:10:26.693Z, PID: 13320] [aspnetcorev2_inprocess.dll] Waiting for file watcher thread to exit.
[2026-06-01T13:10:26.699Z, PID: 13320] [aspnetcorev2_inprocess.dll] Stopping CLR
[2026-06-01T13:10:26.708Z, PID: 13320] [aspnetcorev2_inprocess.dll] Starting shutdown sequence 0
[2026-06-01T13:10:32.192Z, PID: 13320] [aspnetcorev2_inprocess.dll] Drained all requests, notifying managed.
[2026-06-01T13:10:32.194Z, PID: 13320] [aspnetcorev2_inprocess.dll] Waiting for 0 requests to drain
[2026-06-01T13:10:32.383Z, PID: 13320] [aspnetcorev2_inprocess.dll] Managed application exited with code 0
[2026-06-01T13:10:32.386Z, PID: 13320] [aspnetcorev2_inprocess.dll] Clr thread wait ended: clrThreadExited: 1
[2026-06-01T13:10:32.388Z, PID: 13320] [aspnetcorev2_inprocess.dll] Event Log: 'Application 'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE/1_0/MyApp' has shutdown.' 
End Event Log Message.
[2026-06-01T13:10:32.391Z, PID: 13320] [aspnetcorev2_inprocess.dll] Canceling standard stream pipe reader
[2026-06-01T13:10:32.393Z, PID: 13320] [aspnetcorev2_inprocess.dll] Stopping in-process worker thread
[2026-06-01T13:13:30.086Z, PID: 13320] [aspnetcorev2.dll] Received a request during shutdown. Will return a 503 response.
[2026-06-01T13:13:30.092Z, PID: 13320] [aspnetcorev2.dll] Failed HRESULT returned: 0x800704e7 at D:\a\_work\1\s\src\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\AspNetCore\proxymodule.cpp:97 
[2026-06-01T13:13:30.104Z, PID: 13320] [aspnetcorev2.dll] Failed HRESULT returned: 0x800704e7 at D:\a\_work\1\s\src\aspnetcore\src\Servers\IIS\AspNetCoreModuleV2\AspNetCore\proxymodule.cpp:121 
[2026-06-01T13:13:30.602Z, PID: 13320] [aspnetcorev2.dll] Received a request during shutdown. Will return a 503 response.
...

We recreated the scenario with shutdownDelay set to 0 (the case when everything works fine), and we noticed that OnGlobalApplicationStop was not being logged. OnGlobalConfigurationChange was still being logged. Shutdown was not being triggered, so we assumed that OnGlobalApplicationStop was responsible for the issue. In source code we found the following section (globalmodule.cpp):

GLOBAL_NOTIFICATION_STATUS
ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop(
    IN IHttpApplicationStopProvider* pProvider
)
{
    UNREFERENCED_PARAMETER(pProvider);

    // If we're already cleaned up just return.
    // If user has opted out of the new shutdown behavior ignore this call as we never registered for it before
    if (!m_pApplicationManager || m_pApplicationManager->UseLegacyShutdown())
    {
        return GL_NOTIFICATION_CONTINUE;
    }

    LOG_INFO(L"ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop");

    if (!g_fInShutdown && !m_shutdown.joinable())
    {
        // Apps with preload + always running that don't receive a request before recycle/shutdown will never call OnGlobalStopListening
        // IISExpress can also close without calling OnGlobalStopListening which is where we usually would trigger shutdown
        // so we should make sure to shutdown the server in those cases
        StartShutdown();
    }

    return GL_NOTIFICATION_CONTINUE;
}

Here we can see that UseLegacyShutdown causes the method to return early, skipping the StartShutdown call.

Is this intentional or is this a bug?
Why does this work on 8.0.24? We couldn't spot any meaningful changes in the source code.

Thanks for any help!

Here is the full log: logs.txt

Expected Behavior

We are not sure what the expected behavior should be, we see two alternatives:

OnGlobalApplicationStop should not trigger a shutdown and should leave the worker process untouched,
OR
OnGlobalApplicationStop should trigger a shutdown AND should trigger worker process recycling, so a new worker process should be created.

Steps To Reproduce

N/A - let me know if the description is not sufficient.

Exceptions (if any)

No response

.NET Version

N/A

Anything else?

dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Activity

  1. added theissue type on Jun 1, 2026
  2. github-actions commented on Jun 1, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-networking — The issue is in the IIS in-process hosting module (AspNetCoreModuleV2, aspnetcorev2.dll, aspnetcorev2_inprocess.dll) under src/Servers/IIS/. The bug involves OnGlobalApplicationStop, UseLegacyShutdown, and the worker process not being properly recycled after the managed application shuts down.

    Type: Bug — The worker process enters a permanent 503-returning shutdown state after OnGlobalApplicationStop triggers managed app shutdown, but IIS does not recycle the worker process. The issue is a regression from 8.0.27 to 10.0.8.

    Regression Info

    • Previously working version: ASP.NET Core 8.0.27
    • Broken since: ASP.NET Core 10.0.8 (Hosting Bundle 10.0.8)
    • The new (non-legacy) shutdown path introduced in globalmodule.cpp via commit 42bc1a1 causes OnGlobalApplicationStop to call StartShutdown(), which shuts down the managed CLR/application but does not trigger IIS to recycle the worker process (w3wp.exe). The process remains alive but stuck in shutdown state, returning 503 for all subsequent requests. With shutdownDelay=0 (legacy path), OnGlobalApplicationStop is skipped and this code path is never hit, so everything works correctly.

    Potential Duplicates

    • None found — searches for "AspNetCoreModuleV2 shutdown 503 worker process" and "OnGlobalApplicationStop UseLegacyShutdown IIS worker" returned only this issue.

    Notes

    • The root cause appears to be that StartShutdown() in OnGlobalApplicationStop shuts down the in-process application but relies on IIS to subsequently recycle the worker process — which may not happen in all recycle/configuration-change scenarios (e.g., when OnGlobalApplicationStop is triggered by a global IIS config change affecting other apps rather than a direct recycle of this app's pool).
    • The reporter has identified a viable workaround: setting shutdownDelay to 0 in web.config (enabling legacy shutdown), which prevents OnGlobalApplicationStop from triggering shutdown.
    • It may be worth clarifying whether OnGlobalApplicationStop should trigger worker process recycling or simply skip shutdown (leaving IIS to handle it), as the current behavior — shutting down the managed app but leaving the worker process running in a 503 state — appears to be neither intended option.

    Generated by Issue Triage Agent for dotnet/aspnetcore for issue #66958 · sonnet46 717.9K · ◷

  3. added
    area-networking
    on Jun 1, 2026
  4. MihuBot commented on Jun 1, 2026

    @MihuBot
  5. pledwon2 commented on Jun 1, 2026

    @pledwon2
    Author

    I see that in issue 10117 comment it is mentioned that on versions 8.x.x the new behavior is opt-in, so this would explain why we had no issues on 8.0.27.

    Edit: I found in the source code that the default shutdownDelay is indeed 0 on version 8.

  6. BrennanConroy commented on Jun 1, 2026

    @BrennanConroy
    Member
  7. added
    feature-iis
    on Jun 1, 2026
  8. pledwon2 commented on Jun 2, 2026

    @pledwon2
    Author

    We tested v11 preview 4 and it looks like the issue was fixed. Here are the full logs: logs2.txt

    We can see now the following messages:

    [2026-06-02T10:56:05.780Z, PID: 4052] [aspnetcorev2.dll] ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop
    [2026-06-02T10:56:05.790Z, PID: 4052] [aspnetcorev2.dll] Ignoring OnGlobalApplicationStop, OnGlobalStopListening has been called or should be called shortly.
    

    The application continues working, which is the expected behavior.

    Just wanted to note that the message implies that OnGlobalStopListening should be called, but this should not happen in our scenario, right?

    Also, is there a chance for the fix to appear on v10? We are not planning to use version 11, we use only LTS versions.

  9. BrennanConroy commented on Jun 2, 2026

    @BrennanConroy
    Member

    is there a chance for the fix to appear on v10? We are not planning to use version 11, we use only LTS versions.

    Please comment on the issue I linked, trying to get validation from people that the fix works and that other scenarios don't regress. Would also appreciate if you could try out more than the broken scenario to give some confidence that other scenarios did not regress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingfeature-iis

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions