The w3wp process crashes after an app domain recycle


Description

This issue applies to specific on-prem deployments running Sitecore XP 9.1 Update-1 or later versions. Because of a bug in the .NET framework, every time the AppDomain of .NET application is recycled, the w3wp process crashes while processing the first request. After this, IIS restarts the process and the related process resumes normal operation.

To confirm this, find the following two entries in the Application section of the Windows event viewer. The first one, with "Application Error" in the Source column, should be similar to the following:

Faulting application name: w3wp.exe, version: 10.0.16299.15, time stamp: 0x0aeb5595
Faulting module name: clr.dll, version: 4.7.3130.0, time stamp: 0x5b175fed
Exception code: 0xc0000005
Fault offset: 0x0000000000157b7f
Faulting process id: 0x3d80
Faulting application start time: 0x01d4b9548e3bc666
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Report Id: 050088e2-61ac-40b8-bbd6-e17485b11aa1
Faulting package full name:
Faulting package-relative application ID:

The second one, with ".NET Runtime" in the Source column, should be similar to the following:

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an internal error in the .NET Runtime at IP 00007FFB418F7B7F (00007FFB417A0000) with exit code 80131506.

The crash does not add any entries in the logs related to w3wp. In some cases, other roles using .NET applications might not throw any errors but, in other cases, they might log similar to the entries as follows (provided for xConnect as for an example):

Sitecore.XConnect.XdbCollectionUnavailableException : An error occurred while sending the request.
----> System.Net.Http.HttpRequestException : An error occurred while sending the request.
----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive.
----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host

Solution

To resolve the issue, upgrade Sitecore XP instance to Sitecore XP 10.1.2 or later.

Alternatively, consider the following option: