CustomRenderingViewPathCacheClearer handler of the "publish:end:remote" event fails on CD instance


Description

When using the SXA module in a scaled environment, if the name of the database on the CM instance does not match the one on the remote instances, an error might appear in the log records after publishing.

For example, if CM has 2 web databases configured, as "web" and "web2":
CD1 uses a database that is referenced from CM as "web".
CD2 uses a database that is referenced from CM as "web2".

Executing publishing from CM to "web" and "web2" might lead to the following error on CD2:

ERROR One or more exceptions occurred while processing the subscribers to the 'publish:end:remote' event.
Exception[1]: System.InvalidOperationException
Message[1]: Could not find configuration node: databases/database[@id='web2']
Source[1]: Sitecore.Kernel
at Sitecore.Configuration.DefaultFactory.GetConfigNode(String xpath, Boolean assert)
at Sitecore.Configuration.DefaultFactory.CreateObject(....)
at Sitecore.Configuration.DefaultFactory.GetDatabase(String name, Boolean assert)
at Sitecore.Configuration.DefaultFactory.GetDatabase(String name)
at Sitecore.XA.Foundation.Mvc.EventHandlers.CustomRenderingViewPathCacheClearer.
OnPublish(....)
at Sitecore.XA.Foundation.Caching.EventHandlers.
CacheClearerBase.OnPublishEndRemote(...)
at Sitecore.Events.Event.EventSubscribers.RaiseEvent(...)

Solution

To resolve the issue, consider one of the following options: