Apache Lucene open-source search software
SOLR-7381: Uncaught exceptions thrown by tasks in the pool are logged along with submitter's stack trace
Shalin Shekhar Mangare699256bbb02
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a5b92b1f5b7..f860e8a8dcb 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -158,6 +158,7 @@ Other ChangesExecutors#newFixedThreadPool, #newSingleThreadExecutor, #newCachedThreadPool as well asThreadPoolExecutor directly is now forbidden in Solr. MDC keys are now exposed in threadnames automatically so that a thread dump can give hints on what the thread was doing.+ Uncaught exceptions thrown by tasks in the pool are logged along with submitter's stack trace.(shalin)* SOLR-7384: Fix spurious failures in FullSolrCloudDistribCmdsTest. (shalin)diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.javaindex f6f7cf52be6..ac0e85cb4d1 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java@@ -130,6 +130,7 @@ public class ExecutorUtil {String ctxStr = submitterContext != null && !submitterContext.isEmpty() ?submitterContext.toString().replace("/", "//") : "";final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);+ final Exception submitterStackTrace = new Exception("Submitter stack trace");super.execute(new Runnable() {@Overridepublic void run() {@@ -144,8 +145,14 @@ public class ExecutorUtil {}try {command.run();+ } catch (Throwable t) {+ if (t instanceof OutOfMemoryError) {+ throw t;+ }+ log.error("Uncaught exception {} thrown by thread: {}", t, currentThread.getName(), submitterStackTrace);+ throw t;} finally {- if (threadContext != null) {+ if (threadContext != null && !threadContext.isEmpty()) {MDC.setContextMap(threadContext);} else {MDC.clear();