This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 739f01453f97aef6ccdeb936812c2a80bede24ed
Author: David Smiley <[email protected]>
AuthorDate: Tue Aug 25 22:46:08 2026 -0400

    IndexFetcher: skip opening a searcher when the CoreContainer is shutting 
down
    
    A polling fetch that finishes just as the node shuts down calls 
CoreContainer.getCore(), taking a fresh reference to a core the container is 
already tearing down. The container's own close then can't complete, and the 
last decref lands on the indexFetcher thread — so that thread ends up running 
the whole SolrCore.doClose(). If IndexWriter.close() fails there (the fetch has 
just swapped index directories out from under it), directory refcounts are left 
dangling and CachingDirectoryFact [...]
    
    Checking CoreContainer.isShutDown() first avoids taking the reference at 
all; opening a searcher at that point would fail anyway. This narrows the 
window rather than closing it — shutdown can still begin right after the check 
— but it covers the common case, since CoreContainer.shutdown() sets the flag 
before it starts closing cores.
    
    Found while investigating an intermittent 
TestUserManagedReplicationWithAuth failure, where the aborted doClose() never 
reached its ObjectReleaseTracker release and 49 objects were reported leaked.
    
    (cherry picked from commit 9e15873bb516e4a920204dfb2a5ca6b690a32722)
---
 solr/core/src/java/org/apache/solr/handler/IndexFetcher.java | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java 
b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index e39c6eddfff..4a9f14834cd 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -110,6 +110,7 @@ import org.apache.solr.common.util.SolrNamedThreadFactory;
 import org.apache.solr.common.util.StrUtils;
 import org.apache.solr.common.util.SuppressForbidden;
 import org.apache.solr.common.util.URLUtil;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.DirectoryFactory;
 import org.apache.solr.core.DirectoryFactory.DirContext;
 import org.apache.solr.core.IndexDeletionPolicyWrapper;
@@ -1000,7 +1001,14 @@ public class IndexFetcher {
     // must get the latest solrCore object because the one we have might be 
closed because of a
     // reload
     // todo stop keeping solrCore around
-    try (SolrCore core = 
solrCore.getCoreContainer().getCore(solrCore.getName())) {
+    final CoreContainer coreContainer = solrCore.getCoreContainer();
+    if (coreContainer.isShutDown()) {
+      log.info("CoreContainer is shut down, skipping opening a new searcher");
+      // Opening a searcher now would fail anyway, and taking a reference 
would make this thread
+      // the one that runs the core's close -- from which a partial failure 
leaks directories.
+      return;
+    }
+    try (SolrCore core = coreContainer.getCore(solrCore.getName())) {
       if (core == null) {
         return; // core closed, presumably
       }

Reply via email to