One day, while actively working with Microsoft Dynamics 365 Business Central 23 (on-premises), it terminated my user session, and the following message appeared on my screen:

Some time later, business users faced with the same problem and were extremely unsatisfied with it.

The forums suggested checking Session Timeout for the web client, but changing the timeout didn't solve the problem, which was expected, as this message occurred exactly during work.

All my attempts to find another quick solution on the forums haven't been successful, so I had no choice but to figure it out myself.

💡 Accessing Business Central from the web client requires a Business Central Web Server instance on IIS.

The first thing I did was to look at the application pool settings in IIS for the Business Central web server instance, and in those settings I saw that regular recycling at 29 hour intervals is enabled for the application pool:

To check whether there is a connection between the problem and recycling conditions, I ran the recycle in manual mode and noticed that active user sessions were terminated, and the message, "We paused while you were away. Please refresh to continue." was appearing on the screen.

To evaluate the impact of recycling on a Business Central web client, it's helpful to understand the HTTP request processing pipeline in IIS and process recycling.

HTTP Request Processing in IIS

The process of HTTP request processing in IIS is described in the HTTP Request Processing in IIS [2] section of the Introduction to IIS Architectures [3] article:

  1. When a client browser initiates an HTTP request for a resource on the web server, the request is intercepted by the HTTP.sys driver built into the operating system kernel.
  2. HTTP.sys contacts Windows Process Activation Service (WAS) to obtain information from the configuration store.
  3. WAS service is started as a single instance by the system and requests configuration information from the ApplicationHost.config file (%windir%\System32\inetsrv\config\applicationHost.config) [4].
  4. Since this request is received over HTTP, configuration information is obtained from WAS by the World Wide Web Publishing Service (W3SVC), which is required to configure the HTTP protocol listener. The W3SVC contacts WAS to obtain the HTTP requests handler.
  5. The W3SVC service configures HTTP.sys to listen on specific ports (in my case it's port 443) and the IP header.
  6. The WAS service starts the W3WP.exe process for an application pool, if it has not already been started. Each application pool runs in its own dedicated W3WP.exe process.
  7. The W3WP.exe process runs the Microsoft Dynamics 365 Business Central web client, which generates and returns a response to the HTTP.sys driver.
  8. HTTP.sys sends a response to the browser.

Process Recycling

Starting with IIS 6.0, IIS supports worker process isolation mode. Worker process isolation mode isolates all application code in individual worker processes without a performance penalty.

Worker process isolation mode offers process recycling, in which IIS automatically refreshes web applications by restarting their worker processes (W3WP.exe process in the figure above). Process recycling keeps problematic applications running smoothly, and is an especially effective solution in cases where it isn't possible to modify the application code [5].

Process recycling can happen in two ways:

  • The W3SVC service (using WAS) terminates the current W3WP.exe process and creates a new W3WP.exe process in its place;
  • When the W3WP.exe worker process terminates, a new one is started simultaneously. This type of recycling is called overlapped recycling. It is the default for all application pools.

Recycling can be configured to run at fixed times on a regular basis or by specifying events when it is required. The recycling element is configured at the server level in the ApplicationHost.config file.

By default, after installing Microsoft Dynamics 365 Business Central using setup.exe, recycling for the web client is set at regular intervals of 1740 minutes.

Overlapped Recycling

In an overlapped recycling scenario, the process targeted for a recycle continues to process all remaining requests (since HTTP.sys stores the request queue) while a replacement W3WP.exe process is created simultaneously. The new process is started before the old worker process stops, and requests are then directed to the new process. This design prevents delays in service, since the old process continues to accept requests until the new process has initialized successfully, and is instructed to shut down only after the new process is ready to handle requests [5].

IIS settings has an option Shutdown Time Limit, what determines the interval for W3WP.exe worker process to finish all requests before the World Wide Web Publishing Service (W3SVC) terminates it. The default value is 90 seconds, and it means that W3SVC will wait 90 seconds before killing the application pool if it has not shut down after processing remain requests:

The overlapped recycling is the default for all application pools in IIS [8]:

And it would seem that the message, "We paused while you were away. Please refresh to continue." occurs because the queue of remaining requests was not processed within the specified time, but in the case of Microsoft Dynamics 365 Business Central it isn't the only problem, Business Central also simply does not store the states of user sessions, which means that the states of active user sessions are lost, and we see our message.

Why use recycling in Microsoft Dynamics 365 Business Central

So, if the recycling process in Microsoft Dynamics 365 Business Central is so problematic, why bother to use it? Recycling should be used for at least one simple reason - memory leaks in Business Central. I can't say that I dug deep into this issue, but I think that a lot of memory leaks related with subscribing to events in Business Central.

The Business Central Server runs on Microsoft .NET 6 [6], however events in .NET are notorious for causing memory leaks because once you subscribe to an event, that object holds a reference to the class. It means there are objects that are still referenced but are effectually unused. Since they are referenced, the garbage collector won’t collect them, and they will remain forever, taking up memory [7].

So refreshing worker processes can free up a significant amount of memory.

💡 A very useful article on the causes of memory leaks in .NET applications, 8 Ways You can Cause Memory Leaks in .NET [7] by Michael Shpilt.

Best practice for using the recycling in Microsoft Dynamics 365 Business Central

Using the default recycling settings for Microsoft Dynamics 365 Business Central Web Client isn't a good idea, as active user sessions will be terminated every 29 hours, which may break the session of a user who is currently working with some important or urgent tasks.

You should use the regular recycling process in specific time outside of business hours in your organization:

Maintaining Microsoft Dynamics 365 Business Central Web Client running smoothly and why it is important to understand IIS architecture

Alexei Popov
|
September 11, 2024

Business Central vs. Finance and Operations: Navigating the Dual ERP Landscape

Lana Beloš
|
June 6, 2024

Talent as a Service (TaaS): is it a possible way to have an extended team?

Lana Beloš
|
April 25, 2024