You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ma...@apache.org on 2024/06/07 15:28:40 UTC

(solr) branch branch_9x updated: SOLR-17323: Fix potential ConcurrentModificationException on CachingDirectoryFactory.close() (#2505)

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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 0cdc4b4abeb SOLR-17323: Fix potential ConcurrentModificationException on CachingDirectoryFactory.close() (#2505)
0cdc4b4abeb is described below

commit 0cdc4b4abeb547ce285ed3ff9356a868f0fde121
Author: Michael Gibney <mi...@michaelgibney.net>
AuthorDate: Fri Jun 7 11:25:24 2024 -0400

    SOLR-17323: Fix potential ConcurrentModificationException on CachingDirectoryFactory.close() (#2505)
    
    (cherry picked from commit 4d9a0b78d0b40693ee2c50edfa938750aa111d4b)
---
 .../java/org/apache/solr/core/CachingDirectoryFactory.java | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
index a2a062a4f79..dfe9487809e 100644
--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
@@ -139,7 +139,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
       cacheValue.doneWithDir = true;
       log.debug("Done with dir: {}", cacheValue);
       if (cacheValue.refCnt == 0 && !closed) {
-        boolean cl = closeCacheValue(cacheValue);
+        boolean cl = closeCacheValue(cacheValue, null);
         if (cl) {
           removeFromCache(cacheValue);
         }
@@ -198,7 +198,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
           for (CacheValue v : val.closeEntries) {
             assert v.refCnt == 0 : val.refCnt;
             log.debug("Closing directory when closing factory: {}", v.path);
-            boolean cl = closeCacheValue(v);
+            boolean cl = closeCacheValue(v, closedDirs);
             if (cl) {
               closedDirs.add(v);
             }
@@ -231,7 +231,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
 
   // be sure the method is called with the sync lock on this object
   // returns true if we closed the cacheValue, false if it will be closed later
-  private boolean closeCacheValue(CacheValue cacheValue) {
+  private boolean closeCacheValue(CacheValue cacheValue, Set<CacheValue> deferRemove) {
     log.debug("looking to close {} {}", cacheValue.path, cacheValue.closeEntries);
     List<CloseListener> listeners = closeListeners.remove(cacheValue.directory);
     if (listeners != null) {
@@ -279,7 +279,11 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
       } else {
         // this was a deferred close, so it's our responsibility to remove it from cache
         assert val.closeEntries.isEmpty();
-        removeFromCache(val);
+        if (deferRemove == null) {
+          removeFromCache(val);
+        } else {
+          deferRemove.add(val);
+        }
       }
     }
 
@@ -500,7 +504,7 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
       assert cacheValue.refCnt >= 0 : cacheValue.refCnt;
 
       if (cacheValue.refCnt == 0 && cacheValue.doneWithDir && !closed) {
-        boolean cl = closeCacheValue(cacheValue);
+        boolean cl = closeCacheValue(cacheValue, null);
         if (cl) {
           removeFromCache(cacheValue);
         }