Apache Solr open-source search software
SOLR-17720: Fix rare deadlock in CollectionProperties (#3304)
aparnasuresh8567a642fe0263
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 6ece23c3e52..d7e51488214 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -267,6 +267,8 @@ Bug Fixes* SOLR-17294: ConcurrentUpdateSolrClient no longer detects "false-positive" stalls. (Mark Miller, Jason Gerlowski)+* SOLR-17720: Fix rare deadlock in CollectionProperties internals. (Aparna Suresh, Houston Putman)+Dependency Upgrades---------------------* SOLR-17471: Upgrade Lucene to 9.12.1. (Pierre Salagnac, Christine Poerschke)diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionPropertiesZkStateReader.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionPropertiesZkStateReader.javaindex 135251ddd5a..4242e0beee9 100644--- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionPropertiesZkStateReader.java+++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionPropertiesZkStateReader.java@@ -393,19 +393,22 @@ public class CollectionPropertiesZkStateReader implements Closeable {}public void removeCollectionPropsWatcher(String collection, CollectionPropsWatcher watcher) {- collectionPropsObservers.compute(- collection,- (k, v) -> {- if (v == null) return null;- v.stateWatchers.remove(watcher);- if (v.canBeRemoved()) {- // don't want this to happen in middle of other blocks that might add it back.- synchronized (getCollectionLock(collection)) {+ // don't want removal from watchedCollectionProps to happen in middle of other blocks that might+ // add it back.+ // Need to lock outside of the compute() call or risk a deadlock with the locking done in+ // collectionPropsObservers+ synchronized (getCollectionLock(collection)) {+ collectionPropsObservers.compute(+ collection,+ (k, v) -> {+ if (v == null) return null;+ v.stateWatchers.remove(watcher);+ if (v.canBeRemoved()) {watchedCollectionProps.remove(collection);return null;}- }- return v;- });+ return v;+ });+ }}}