Prolonged Application Pool shut down in case of kept-alive connections
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
We're seeing Application Pools taking unnecessarily long time to shut down when running apps with ANCM.
When we're stopping Application Pool, underlying application is finishing and exiting properly in under a second (can be easily confirmed when running in `OutOfProcess` mode - dotnet process disappears). But the Pool is still in Stopping state until `Shutdown Time Limit (seconds)` (default 90) configured on the Pool is reached.
We've narrowed it down to browsers issuing requests with `Connection: keep-alive` header and `Connection Timeout` (default 120) configured in the `Limits` section for IIS Web Site.
This can be reproduced with simple Hello World application. Issue request from a browser (tested with Chrome), keep the browser open. Execute `Measure-Command {.\appcmd.exe stop apppool /apppool.name:"temp"| Out-Default}` to stop the pool and check how long it takes. If browser is completely closed or there were no requests made or if connection is forcibly closed (say with Sysinternals TcpView) - Pool stops immediately. If browser is kept open - Pool stops when either `Shutdown Time Limit (seconds)` or `Connection Timeout` is reached depending on which one is lower (and of course depending on when the command was executed).
During deployment of our apps we're waiting for Application Pools to completely shut down. In some cases it's hundreds of Pools to deal with sequentially hence takes quite long.
Given that underlying application stops within seconds, is no longer running and no longer able to take any requests - it seems there's no more need to keep the connections open.
Can this be improved/fixed in ANCM? Maybe it's not even ANCM issue?
Contributor guide
Assessment
This issue has not been assessed yet.