Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-14686: fix MDC log clear in SolrCore.close (#583)

David Smiley703782d1a1f6
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index d3604a2be56..dc3887d8787 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -1573,13 +1573,20 @@ public final class SolrCore implements SolrInfoBean, Closeable {
*/
@Override
public void close() {
- int count = refCount.decrementAndGet();
- if (count > 0) return; // close is called often, and only actually closes if nothing is using it.
- if (count < 0) {
- log.error("Too many close [count:{}] on {}. Please report this exception to [email protected]", count, this);
- assert false : "Too many closes on SolrCore";
- return;
+ try {
+ int count = refCount.decrementAndGet();
+ if (count < 0) {
+ log.error("Too many close [count:{}] on {}. Please report this exception to [email protected]", count, this);
+ assert false : "Too many closes on SolrCore";
+ } else if (count == 0) {
+ doClose();
+ }
+ } finally {
+ MDCLoggingContext.clear(); // balance out from SolrCore open with close
}
+ }
+
+ private void doClose() {
log.info("CLOSING SolrCore {}", this);
ExecutorUtil.shutdownAndAwaitTermination(coreAsyncTaskExecutor);
@@ -1720,8 +1727,6 @@ public final class SolrCore implements SolrInfoBean, Closeable {
}
}
- MDCLoggingContext.clear(); // balance out open with close
-
assert ObjectReleaseTracker.release(this);
}