questions about IIS application pool configuration - iis

I have some questions about IIS application pool configuration.
I know that idleTimeout specifies how long a worker process should run idle if no new requests are received and the worker process is not processing requests. After the allocated time passes, the worker process should request that it be shut down by the WWW service (taken from here). My question is when and how the worker process starts when a request arrives after it shut down?
Other question is what is the difference between application pool recycling and between shut down? Does it better to recycke instead of shut down and then start again?

When and How worker process starts? When a new request comes in IIS spins a new process for the app pool your website is running under.
The difference between shutting down and recycle is that during a recycle a new process is started for the app pool in parallel, while the existing process is still serving an existing request. Any new requests that come in are handled by the new process. So in effect you do not loose any request that come in and any existing requests are not prematurely dropped. In a shutdown, you will loose the requests while the app is down.
To see this live in action - open task manager, select processes tab and see IIS spin up the app pool processes and notice the behavior between a shutdown and recycle. During a recycle for a brief moment you will see two processes for the same app pool.
See this video for a better understanding : http://dotnetslackers.com/articles/iis/IIS-Overlapping-App-Pools-Week-16.aspx

Related

How to keep Blazor Server connection active when IIS is recycling the application pool

I am building a Blazor Server intranet application for my customer. One of the requirements is that they can stay logged in indefinitely. If they starting inputting some data on a Friday afternoon, they should be able to return on Monday morning and continue working without interruption.
I came to observe that the client-side was getting disconnected from the server about once per day. When this happened I would see the dreaded Blazor error “Reconnection failed. Try reloading the page if you’re unable to reconnect.”. If I click the link to Reload, it immediately reconnects to my server, but any work in process would be lost.
I found the root cause: by default, IIS is recycling the application pool every 29 hours. When this happens, the Blazor SignalR connection is getting interrupted, and hence the code running in the browser times out and disconnects.
I am able to work around this issue by disabling application pool recycling altogether. So far, it looks like that works fine (I could keep connectivity for the past 3 days). But I am worried this may not be safe long term, since application pool recycling helps deal with issues such as memory leaks, fragmentation, etc.
SO, my question is: is it possible to configure IIS in way that I can recycle the application pool AND also keep my blazor server connection available during that recycle period?
When you recycle an application pool, HTTP.SYS holds onto the client connection in kernel mode while the user mode worker process recycles. After the process recycle, HTTP.SYS transparently routes the new requests to the new worker process. Thus, the client never "loses all connectivity" to the server - the TCP connection is never lost - and never notices the process recycle.
I believe your problem is with the applications running in your application pool that store state within the process, such as whether a user is logged in or not. Everytime the process recycles, that state is automatically lost... which is by-design since that is what a process recycle accomplishes. As a result, your users "lose all connectivity" and "have to log back into their applications" to re-establish that lost state. The only way to fix this is for your applications to store its state outside of the IIS worker process such that it is friendly to being recycled.
The following blog entry talks more about what is going on:
https://learn.microsoft.com/en-us/archive/blogs/david.wang/why-do-i-lose-asp-session-state-on-iis6

How to better handle IIS app pool recycle in web services

I am running a web service in IIS which calls a third party vendor application. The web service is called from yet another third party application to which the IIS hosted web service replies to. So basically My App -> IIS App -> Third Party App -> IIS App-> My App.
Occasionally, there are app pool recycles which the Third party App is executing, meaning the IIS app is waiting for the reply. This causes the My App to indefinitely wait on the Third Party app because the singnalling chain is now broken.
Is it by design that IIS will force kill the child process running in it during recycles? Is there a way to make the recycle wait till the child is completed?
Did you set Disable Overlapped Reycle
If you set it to true, then IIS recycle will terminate the old process instance and create a new one immediately.
How if you were setting it to false, Then IIS Recycling will not terminate old process and requests immediately. You can see there are two instance side by side if the old process haven't finish all requests.
It will create a new application pool as well. The difference is IIS will leave the old process until all requests in old worker process being finished or shut down time exceed the ShutDown Time limit. Its default value is 90
So if your old request didn't hang in the old worker process and it require more than 90s to finish the request, please just expand the value of ShutDown Time Limit. It will give your old process more time to handle current requests.

Application pool recycling — doesn't recover

I have an ASP.NET Core app — a RESTful API with websocket functionality through SignalR.
We have an issue when the application pool is recycled automatically every 29 hours - sometimes (rarely) it doesn't recover. Even manually, I can't restart the application pool.
Yesterday the only thing that helped was restarting the w3 publishing service.
By looking through logs I can see one moment the server responds nicely and fast with code 200 responses, then next it's all code 400 responses (?) and shortly thereafter 503.
Any idea what could be preventing it from recycling. The event log states in order:
A worker process with process id of '29752' serving application pool 'DefaultAppPool' has requested a recycle because the worker process reached its allowed processing time limit.
A worker process '29752' serving application pool 'DefaultAppPool' failed to stop a listener channel for protocol 'http' in the allotted time. The data field contains the error number.
Binary data:
In Words
0000: 800705B4
A process serving application pool 'DefaultAppPool' exceeded time limits during shut down. The process id was '29752'.

what is meant by "failure" in IIS rapid fail protection?

according to the the IIS documentation the rapid fail protection once activated leads to the deactivation of an application pool if a "failure" occurs. However, I could not find the definition of the "failure" case. In my web application I have a special exception that I would like the IIS to consider it as a "failure".
Does anyone have an idea? Thanks
This appears to have a list, for Server 2003 at least: http://web.archive.org/web/20130511004652/http://technet.microsoft.com/en-us/library/cc787273(WS.10).aspx
The WWW service shuts down an application pool whenever a worker
process in the application pool fails often enough to equal or exceed
the Rapid-Fail Protection (RFP) interval time window (for example:
five failures in five minutes). The WWW service detects failure
whenever:
A worker process does not start within the startup time limit.
A worker process does not shut down within the shutdown time limit.
A worker process shuts itself down because of a fatal error and sends
the WWW service an error code.
A worker process fails to respond to a ping message.
The WWW service detects that a worker process is sending non-standard
communications (the worker process may have been taken over).
(updated with archive.org to fix broken link, and replicated detail here)
The documentation for configuring rapid fail protection alludes to a "failure" meaning a worker process crash.
Through experimentation I've noticed that you should expect something like the following in Windows Event Application Logs for a w3wp.exe crash:
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/1/ROOT
Process ID: 2628
Exception: System.SomeUnhandledException
Indeed with rapid fail protection enabled with the default configuration, 5 such events within 5 minutes of each other cause the application pool to stop, and you'll see a further Windows Event Application Log similar to:
Application pool 'my-test-application-pool' is being automatically
disabled due to a series of failures in the process(es) serving that
application pool.

Recycle AppPool

Is Recycling an App Pool programatically the same as starting and stopping the app pool in IIS.
Kind of, the difference being that during a recycle http.sys keeps the client connection alive whilst the worker process recycles and transparently routes new requests to the new worker process once it's started.
Also IIS (6 and 7) defaults to using "Overlapped Recycling". What this means is that IIS will start a new worker process before it shuts down the old worker process. Once the new process is started all new requests are directed to the new process.
If you stop and start the application pool you will dump all of your client connections and users may receive a Service Unavailable message whilst the new pool is being started.
Additional differences are:
You can do recycle to your application pool only, while stop & start influences all application pools.
When you are asking to recycle you have time to finalize your work (like saving your data etc.), which is not in restart.
You can schedule the IIS to run the recycle job depends on specific time, after period of time, depends on your memory consumption etc..

Resources