The IP address of the Solr server gets cached on the .NET level. This behavior might lead to connection issues if the solr.search connection string value is a domain name instead of a static IP address. If the DNS mapping for the domain is changed to a new IP address, the changes are not picked up by Sitecore instances until the instances have been restarted.
This is a common scenario when using SearchStax Disaster Recovery. This article provides recommendations on how to reestablish connection to Solr when the DNS is updated to point to a new IP address.
To reestablish connection to Solr when the DNS is updated to point to a new IP address, consider one of the following options:
using System; using System.Globalization; using HttpWebAdapters; using CommonServiceLocator; using Microsoft.Extensions.DependencyInjection; using Sitecore; using Sitecore.ContentSearch.SolrProvider.Abstractions; namespace YourNamespace { public class ResettableConnectionHttpWebRequestFactory : IHttpWebRequestFactory { private IHttpWebRequestFactory _httpWebRequestFactory; private readonly int _connectionLeaseTimeout; private static readonly TimeSpan DefaultConnectionLeaseTimeout = TimeSpan.FromMinutes(4); public ResettableConnectionHttpWebRequestFactory(string connectionLeaseTimeout) { _connectionLeaseTimeout = (int)DateUtil.ParseTimeSpan(connectionLeaseTimeout, DefaultConnectionLeaseTimeout, CultureInfo.CurrentCulture) .TotalMilliseconds; } public IHttpWebRequest Create(Uri url) { var request = GetHttpWebRequestFactory().Create(url); request.ServicePoint.ConnectionLeaseTimeout = _connectionLeaseTimeout; return request; } private IHttpWebRequestFactory GetHttpWebRequestFactory() { if (_httpWebRequestFactory != null) return _httpWebRequestFactory; return _httpWebRequestFactory = CreateHttpWebRequestFactory(); } private IHttpWebRequestFactory CreateHttpWebRequestFactory() { IHttpWebRequestFactory resultFactory; var solrAddress = ServiceLocator.Current.GetService<BaseSolrSpecificSettings>().SolrAddress(); if (solrAddress != null && solrAddress.UseBaseAuthentication) { resultFactory = new BasicAuthHttpWebRequestFactory(solrAddress.Username, solrAddress.Password); } else { resultFactory = new HttpWebRequestFactory(); } return resultFactory; } } }Note: Add references to the following assemblies used by Sitecore:
<?xml version="1.0" encoding="utf-8"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/"> <sitecore search:require="solr"> <contentSearch> <indexConfigurations> <solrHttpWebRequestFactory type="YourNamespace.ResettableConnectionHttpWebRequestFactory, YourDll"> <param desc="connectionLeaseTimeout">00:03:00</param> </solrHttpWebRequestFactory> </indexConfigurations> </contentSearch> </sitecore> </configuration>