Apache Solr open-source search software
SOLR-4992: Solr eats OutOfMemoryError exceptions in many cases.
Mark Robert Millercb23c8ba3c29
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 6d391d07eef..167b3575d6d 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -200,6 +200,9 @@ Bug Fixes* SOLR-5567: ZkController getHostAddress duplicates url prefix.(Kyle Halliday, Alexey Serba, shalin)+* SOLR-4992: Solr eats OutOfMemoryError exceptions in many cases.+ (Mark Miller, Daniel Collins)+Optimizations----------------------diff --git a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2StemmerFactory.java b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2StemmerFactory.javaindex 8db24d0a593..d0e7abd7ca8 100644--- a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2StemmerFactory.java+++ b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2StemmerFactory.java@@ -224,7 +224,7 @@ public class LuceneCarrot2StemmerFactory implements IStemmerFactory {public static IStemmer createStemmer() {try {return new LuceneStemmerAdapter();- } catch (Throwable e) {+ } catch (Exception e) {return IdentityStemmer.INSTANCE;}}diff --git a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2TokenizerFactory.java b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2TokenizerFactory.javaindex 88c3b737e3b..28fa893cab9 100644--- a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2TokenizerFactory.java+++ b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/LuceneCarrot2TokenizerFactory.java@@ -82,6 +82,9 @@ public class LuceneCarrot2TokenizerFactory implements ITokenizerFactory {.warn("Could not instantiate Smart Chinese Analyzer, clustering quality "+ "of Chinese content may be degraded. For best quality clusters, "+ "make sure Lucene's Smart Chinese Analyzer JAR is in the classpath");+ if (e instanceof Error) {+ throw (Error) e;+ }}}@@ -89,6 +92,9 @@ public class LuceneCarrot2TokenizerFactory implements ITokenizerFactory {try {return new ChineseTokenizer();} catch (Throwable e) {+ if (e instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) e;+ }return new ExtendedWhitespaceTokenizer();}}diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.javaindex 61f9b3ccf7d..4171bb69d4f 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImportHandler.java@@ -101,7 +101,7 @@ public class DataImportHandler extends RequestHandlerBase implements}debugEnabled = StrUtils.parseBool((String)initArgs.get(ENABLE_DEBUG), true);importer = new DataImporter(core, myName);- } catch (Throwable e) {+ } catch (Exception e) {LOG.error( DataImporter.MSG.LOAD_EXP, e);throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, DataImporter.MSG.LOAD_EXP, e);}diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImporter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImporter.javaindex d76119450d1..9862ba4f276 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImporter.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DataImporter.java@@ -402,7 +402,7 @@ public class DataImporter {public void doFullImport(SolrWriter writer, RequestInfo requestParams) {LOG.info("Starting Full Import");setStatus(Status.RUNNING_FULL_DUMP);-+ boolean success = false;try {DIHProperties dihPropWriter = createPropertyWriter();setIndexStartTime(dihPropWriter.getCurrentTimestamp());@@ -411,10 +411,14 @@ public class DataImporter {docBuilder.execute();if (!requestParams.isDebug())cumulativeStatistics.add(docBuilder.importStatistics);- } catch (Throwable t) {- SolrException.log(LOG, "Full Import failed", t);- docBuilder.rollback();+ success = true;+ } catch (Exception e) {+ SolrException.log(LOG, "Full Import failed", e);} finally {+ if (!success) {+ docBuilder.rollback();+ }+setStatus(Status.IDLE);DocBuilder.INSTANCE.set(null);}@@ -431,7 +435,7 @@ public class DataImporter {public void doDeltaImport(SolrWriter writer, RequestInfo requestParams) {LOG.info("Starting Delta Import");setStatus(Status.RUNNING_DELTA_DUMP);-+ boolean success = false;try {DIHProperties dihPropWriter = createPropertyWriter();setIndexStartTime(dihPropWriter.getCurrentTimestamp());@@ -440,10 +444,13 @@ public class DataImporter {docBuilder.execute();if (!requestParams.isDebug())cumulativeStatistics.add(docBuilder.importStatistics);- } catch (Throwable t) {- LOG.error("Delta Import Failed", t);- docBuilder.rollback();+ success = true;+ } catch (Exception e) {+ LOG.error("Delta Import Failed", e);} finally {+ if (!success) {+ docBuilder.rollback();+ }setStatus(Status.IDLE);DocBuilder.INSTANCE.set(null);}diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.javaindex dc33a31ea89..68efd9b1dac 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java@@ -538,7 +538,7 @@ public class DocBuilder {throw e;} elsethrow e;- } catch (Throwable t) {+ } catch (Exception t) {if (verboseDebug) {getDebugLogger().log(DIHLogLevels.ENTITY_EXCEPTION, epw.getEntity().getName(), t);}diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.javaindex e9c7b2af7e8..a87745e1433 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrWriter.java@@ -105,8 +105,8 @@ public class SolrWriter extends DIHWriterBase implements DIHWriter {try {CommitUpdateCommand commit = new CommitUpdateCommand(req,optimize);processor.processCommit(commit);- } catch (Throwable t) {- log.error("Exception while solr commit.", t);+ } catch (Exception e) {+ log.error("Exception while solr commit.", e);}}@@ -115,8 +115,8 @@ public class SolrWriter extends DIHWriterBase implements DIHWriter {try {RollbackUpdateCommand rollback = new RollbackUpdateCommand(req);processor.processRollback(rollback);- } catch (Throwable t) {- log.error("Exception while solr rollback.", t);+ } catch (Exception e) {+ log.error("Exception while solr rollback.", e);}}diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.javaindex 40285e3b2e2..d839f277605 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.java@@ -92,7 +92,7 @@ public class ZKPropertiesWriter extends SimplePropertiesWriter {if (data != null) {props.load(new StringReader(new String(data, "UTF-8")));}- } catch (Throwable e) {+ } catch (Exception e) {log.warn("Could not read DIH properties from " + path + " :" + e.getClass(), e);}diff --git a/solr/core/src/java/org/apache/solr/SolrLogFormatter.java b/solr/core/src/java/org/apache/solr/SolrLogFormatter.javaindex d6636e8a30f..55c01e1eef5 100644--- a/solr/core/src/java/org/apache/solr/SolrLogFormatter.java+++ b/solr/core/src/java/org/apache/solr/SolrLogFormatter.java@@ -114,9 +114,9 @@ public class SolrLogFormatter extends Formatter {public String format(LogRecord record) {try {return _format(record);- } catch (Throwable th) {+ } catch (Exception e) {// logging swallows exceptions, so if we hit an exception we need to convert it to a string to see it- return "ERROR IN SolrLogFormatter! original message:" + record.getMessage() + "\n\tException: " + SolrException.toStr(th);+ return "ERROR IN SolrLogFormatter! original message:" + record.getMessage() + "\n\tException: " + SolrException.toStr(e);}}@@ -415,7 +415,7 @@ sb.append("(group_name=").append(tg.getName()).append(")");public void run() {try {go();- } catch (Throwable e) {+ } catch (Exception e) {e.printStackTrace();}}diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.javaindex 0bbc8db2a1c..301dc957484 100644--- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java+++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java@@ -209,8 +209,8 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {boolean success = false;try {success = syncStrategy.sync(zkController, core, leaderProps);- } catch (Throwable t) {- SolrException.log(log, "Exception while trying to sync", t);+ } catch (Exception e) {+ SolrException.log(log, "Exception while trying to sync", e);success = false;}@@ -268,12 +268,13 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {core.close();}}-+ boolean success = false;try {super.runLeaderProcess(weAreReplacement);- } catch (Throwable t) {- SolrException.log(log, "There was a problem trying to register as the leader", t);- cancelElection();+ success = true;+ } catch (Exception e) {+ SolrException.log(log, "There was a problem trying to register as the leader", e);+try {core = cc.getCore(coreName);if (core == null) {@@ -287,9 +288,16 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {// we could not publish ourselves as leader - rejoin electionrejoinLeaderElection(leaderSeqPath, core);} finally {- if (core != null) {- core.close();+ try {+ if (!success) {+ cancelElection();+ }+ } finally {+ if (core != null) {+ core.close();+ }}+}}@@ -386,11 +394,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {cancelElection();- try {- core.getUpdateHandler().getSolrCoreState().doRecovery(cc, core.getCoreDescriptor());- } catch (Throwable t) {- SolrException.log(log, "Error trying to start recovery", t);- }+ core.getUpdateHandler().getSolrCoreState().doRecovery(cc, core.getCoreDescriptor());leaderElector.joinElection(this, true);}diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.javaindex f8b2f7a6902..89c14ba062f 100644--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java@@ -963,6 +963,7 @@ public class Overseer {private String adminPath;+ // overseer not responsible for closing readerpublic Overseer(ShardHandler shardHandler, String adminPath, final ZkStateReader reader) throws KeeperException, InterruptedException {this.reader = reader;this.shardHandler = shardHandler;@@ -992,20 +993,24 @@ public class Overseer {}public void close() {- if (updaterThread != null) {- try {- updaterThread.close();- updaterThread.interrupt();- } catch (Throwable t) {- log.error("Error closing updaterThread", t);+ try {+ if (updaterThread != null) {+ try {+ updaterThread.close();+ updaterThread.interrupt();+ } catch (Exception e) {+ log.error("Error closing updaterThread", e);+ }}- }- if (ccThread != null) {- try {- ccThread.close();- ccThread.interrupt();- } catch (Throwable t) {- log.error("Error closing ccThread", t);+ } finally {++ if (ccThread != null) {+ try {+ ccThread.close();+ ccThread.interrupt();+ } catch (Exception e) {+ log.error("Error closing ccThread", e);+ }}}updaterThread = null;diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.javaindex 9192445d778..fa01d42266d 100644--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java@@ -189,7 +189,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {} catch (InterruptedException e) {Thread.currentThread().interrupt();return;- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, "", e);}}@@ -255,13 +255,13 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {+ operation);}- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log, "Collection " + operation + " of " + operation- + " failed", t);- results.add("Operation " + operation + " caused exception:", t);+ + " failed", e);+ results.add("Operation " + operation + " caused exception:", e);SimpleOrderedMap nl = new SimpleOrderedMap();- nl.add("msg", t.getMessage());- nl.add("rspCode", t instanceof SolrException ? ((SolrException)t).code() : -1);+ nl.add("msg", e.getMessage());+ nl.add("rspCode", e instanceof SolrException ? ((SolrException)e).code() : -1);results.add("exception", nl);}diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.javaindex 8b8f36dea8e..805fb754054 100644--- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java+++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java@@ -245,15 +245,15 @@ public class RecoveryStrategy extends Thread implements ClosableThread {try {doRecovery(core);- } catch (InterruptedException e) {+ } catch (InterruptedException e) {Thread.currentThread().interrupt();SolrException.log(log, "", e);throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "",e);- } catch (Throwable t) {- log.error("", t);+ } catch (Exception e) {+ log.error("", e);throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,- "", t);+ "", e);}} finally {if (core != null) core.close();@@ -282,8 +282,8 @@ public class RecoveryStrategy extends Thread implements ClosableThread {try {recentUpdates = ulog.getRecentUpdates();recentVersions = recentUpdates.getVersions(ulog.numRecordsToKeep);- } catch (Throwable t) {- SolrException.log(log, "Corrupt tlog - ignoring. core=" + coreName, t);+ } catch (Exception e) {+ SolrException.log(log, "Corrupt tlog - ignoring. core=" + coreName, e);recentVersions = new ArrayList<Long>(0);} finally {if (recentUpdates != null) {@@ -311,8 +311,8 @@ public class RecoveryStrategy extends Thread implements ClosableThread {}log.info("###### startupVersions=" + startingVersions);- } catch (Throwable t) {- SolrException.log(log, "Error getting recent versions. core=" + coreName, t);+ } catch (Exception e) {+ SolrException.log(log, "Error getting recent versions. core=" + coreName, e);recentVersions = new ArrayList<Long>(0);}}@@ -331,9 +331,9 @@ public class RecoveryStrategy extends Thread implements ClosableThread {+ coreName);firstTime = false; // skip peersync}- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log, "Error trying to get ulog starting operation. core="- + coreName, t);+ + coreName, e);firstTime = false; // skip peersync}}@@ -449,21 +449,21 @@ public class RecoveryStrategy extends Thread implements ClosableThread {Thread.currentThread().interrupt();log.warn("Recovery was interrupted", e);retries = INTERRUPTED;- } catch (Throwable t) {- SolrException.log(log, "Error while trying to recover", t);+ } catch (Exception e) {+ SolrException.log(log, "Error while trying to recover", e);} finally {if (!replayed) {try {ulog.dropBufferedUpdates();- } catch (Throwable t) {- SolrException.log(log, "", t);+ } catch (Exception e) {+ SolrException.log(log, "", e);}}}- } catch (Throwable t) {- SolrException.log(log, "Error while trying to recover. core=" + coreName, t);+ } catch (Exception e) {+ SolrException.log(log, "Error while trying to recover. core=" + coreName, e);}if (!successfulRecovery) {@@ -486,9 +486,9 @@ public class RecoveryStrategy extends Thread implements ClosableThread {try {recoveryFailed(core, zkController, baseUrl, coreZkNodeName,core.getCoreDescriptor());- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log,- "Could not publish that recovery failed", t);+ "Could not publish that recovery failed", e);}} else {SolrException.log(log,@@ -496,15 +496,15 @@ public class RecoveryStrategy extends Thread implements ClosableThread {try {recoveryFailed(core, zkController, baseUrl, coreZkNodeName,core.getCoreDescriptor());- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log,- "Could not publish that recovery failed", t);+ "Could not publish that recovery failed", e);}}break;}- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, "core=" + coreName, e);}diff --git a/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java b/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.javaindex 248cbdc35ed..dc4e76132d2 100644--- a/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java+++ b/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java@@ -121,7 +121,7 @@ public class SolrZkServer {zkServer.runFromConfig(sc);}log.info("ZooKeeper Server exited.");- } catch (Throwable e) {+ } catch (Exception e) {log.error("ZooKeeper Server ERROR", e);throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);}diff --git a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.javaindex a3c04cfa24c..7eacf61f264 100644--- a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java+++ b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java@@ -211,8 +211,8 @@ public class SyncStrategy {} else {requestRecovery(leaderProps, ((ShardCoreRequest)srsp.getShardRequest()).baseUrl, ((ShardCoreRequest)srsp.getShardRequest()).coreName);}- } catch (Throwable t) {- SolrException.log(log, ZkCoreNodeProps.getCoreUrl(leaderProps) + ": Could not tell a replica to recover", t);+ } catch (Exception e) {+ SolrException.log(log, ZkCoreNodeProps.getCoreUrl(leaderProps) + ": Could not tell a replica to recover", e);}} else {log.info(ZkCoreNodeProps.getCoreUrl(leaderProps) + ": " + " sync completed with " + srsp.getShardAddress());@@ -278,6 +278,9 @@ public class SyncStrategy {server.request(recoverRequestCmd);} catch (Throwable t) {SolrException.log(log, ZkCoreNodeProps.getCoreUrl(leaderProps) + ": Could not tell a replica to recover", t);+ if (t instanceof Error) {+ throw (Error) t;+ }} finally {server.shutdown();}diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.javaindex bafe65031d0..39fdc92c0bb 100644--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java@@ -249,8 +249,8 @@ public final class ZkController {// with connection losstry {register(descriptor.getName(), descriptor, true, true);- } catch (Throwable t) {- SolrException.log(log, "Error registering SolrCore", t);+ } catch (Exception e) {+ SolrException.log(log, "Error registering SolrCore", e);}}}@@ -385,33 +385,38 @@ public final class ZkController {*/public void close() {this.isClosed = true;-- for (ElectionContext context : electionContexts.values()) {+ try {+ for (ElectionContext context : electionContexts.values()) {+ try {+ context.close();+ } catch (Exception e) {+ log.error("Error closing overseer", e);+ }+ }+ } finally {try {- context.close();- } catch (Throwable t) {- log.error("Error closing overseer", t);+ try {+ overseer.close();+ } catch (Exception e) {+ log.error("Error closing overseer", e);+ }+ } finally {+ try {+ try {+ zkStateReader.close();+ } catch (Exception e) {+ log.error("Error closing zkStateReader", e);+ }+ } finally {+ try {+ zkClient.close();+ } catch (Exception e) {+ log.error("Error closing zkClient", e);+ }+ }}}- try {- overseer.close();- } catch(Throwable t) {- log.error("Error closing overseer", t);- }-- try {- zkStateReader.close();- } catch(Throwable t) {- log.error("Error closing zkStateReader", t);- }-- try {- zkClient.close();;- } catch(Throwable t) {- log.error("Error closing zkClient", t);- }-}/**@@ -473,7 +478,7 @@ public final class ZkController {}}}- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log,"Error while looking for a better host name than 127.0.0.1", e);}diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.javaindex 60c4131abbb..5cbcdbe839f 100644--- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java@@ -186,8 +186,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {}}assert val.refCnt == 0 : val.refCnt;- } catch (Throwable t) {- SolrException.log(log, "Error closing directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error closing directory", e);}}@@ -203,8 +203,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {closedDirs.add(v);}}- } catch (Throwable t) {- SolrException.log(log, "Error closing directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error closing directory", e);}}@@ -212,8 +212,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {log.info("Removing directory after core close: " + val.path);try {removeDirectory(val);- } catch (Throwable t) {- SolrException.log(log, "Error removing directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error removing directory", e);}}@@ -238,8 +238,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {for (CloseListener listener : listeners) {try {listener.preClose();- } catch (Throwable t) {- SolrException.log(log, "Error executing preClose for directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error executing preClose for directory", e);}}}@@ -279,8 +279,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {log.info("Removing directory before core close: " + val.path);try {removeDirectory(val);- } catch (Throwable t) {- SolrException.log(log, "Error removing directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error removing directory", e);}} else {removeEntries.add(val);@@ -291,8 +291,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {for (CloseListener listener : listeners) {try {listener.postClose();- } catch (Throwable t) {- SolrException.log(log, "Error executing postClose for directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error executing postClose for directory", e);}}}@@ -303,8 +303,8 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {try {log.info("Closing directory: " + val.path);val.directory.close();- } catch (Throwable t) {- SolrException.log(log, "Error closing directory", t);+ } catch (Exception e) {+ SolrException.log(log, "Error closing directory", e);}}diff --git a/solr/core/src/java/org/apache/solr/core/Config.java b/solr/core/src/java/org/apache/solr/core/Config.javaindex 82c044fa0e8..2e79b315163 100644--- a/solr/core/src/java/org/apache/solr/core/Config.java+++ b/solr/core/src/java/org/apache/solr/core/Config.java@@ -260,7 +260,7 @@ public class Config {throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e);} catch (SolrException e) {throw(e);- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log,"Error in xpath",e);throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e);}@@ -290,7 +290,7 @@ public class Config {throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e);} catch (SolrException e) {throw(e);- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log,"Error in xpath",e);throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e);}diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSolr.java b/solr/core/src/java/org/apache/solr/core/ConfigSolr.javaindex 78f70d0a066..b0983b6ef4b 100644--- a/solr/core/src/java/org/apache/solr/core/ConfigSolr.java+++ b/solr/core/src/java/org/apache/solr/core/ConfigSolr.java@@ -19,6 +19,7 @@ package org.apache.solr.core;import com.google.common.base.Charsets;import com.google.common.io.ByteStreams;+import org.apache.commons.io.IOUtils;import org.apache.solr.common.SolrException;import org.apache.solr.logging.LogWatcherConfig;@@ -33,6 +34,7 @@ import org.xml.sax.InputSource;import javax.xml.xpath.XPath;import javax.xml.xpath.XPathConstants;import javax.xml.xpath.XPathExpressionException;+import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;@@ -288,7 +290,7 @@ public abstract class ConfigSolr {try {return readProperties(((NodeList) config.evaluate(path, XPathConstants.NODESET)).item(0));- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, null, e);}return null;diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex d4748510e7a..37c7ca45d0c 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -257,21 +257,24 @@ public class CoreContainer {}c = create(cd);registerCore(cd.isTransient(), name, c, false, false);- } catch (Throwable t) {+ } catch (Exception e) {+ SolrException.log(log, null, e);+ try {/* if (isZooKeeperAware()) {try {zkSys.zkController.unregister(name, cd);- } catch (InterruptedException e) {+ } catch (InterruptedException e2) {Thread.currentThread().interrupt();- SolrException.log(log, null, e);- } catch (KeeperException e) {- SolrException.log(log, null, e);+ SolrException.log(log, null, e2);+ } catch (KeeperException e3) {+ SolrException.log(log, null, e3);}}*/- SolrException.log(log, null, t);- if (c != null) {- c.close();- }+ } finally {+ if (c != null) {+ c.close();+ }+ }}return c;}@@ -279,8 +282,8 @@ public class CoreContainer {pending.add(completionService.submit(task));}- } catch (Throwable ex) {- SolrException.log(log, null, ex);+ } catch (Exception e) {+ SolrException.log(log, null, e);}}@@ -416,8 +419,8 @@ public class CoreContainer {for (SolrCore core : cores) {try {core.getSolrCoreState().cancelRecovery();- } catch (Throwable t) {- SolrException.log(log, "Error canceling recovery for core", t);+ } catch (Exception e) {+ SolrException.log(log, "Error canceling recovery for core", e);}}}diff --git a/solr/core/src/java/org/apache/solr/core/Diagnostics.java b/solr/core/src/java/org/apache/solr/core/Diagnostics.javaindex 84c76e04550..efa981faf3c 100644--- a/solr/core/src/java/org/apache/solr/core/Diagnostics.java+++ b/solr/core/src/java/org/apache/solr/core/Diagnostics.java@@ -33,8 +33,8 @@ public class Diagnostics {public static void call(Callable callable, Object... data) {try {callable.call(data);- } catch (Throwable th) {- log.error("TEST HOOK EXCEPTION", th);+ } catch (Exception e) {+ log.error("TEST HOOK EXCEPTION", e);}}diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.javaindex ddc1723f766..8770edd8005 100644--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java@@ -834,7 +834,11 @@ public final class SolrCore implements SolrInfoMBean {} catch (Throwable e) {latch.countDown();//release the latch, otherwise we block trying to do the close. This should be fine, since counting down on a latch of 0 is still fine//close down the searcher and any other resources, if it exists, as this is not recoverable+ if (e instanceof OutOfMemoryError) {+ throw (OutOfMemoryError)e;+ }close();+throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e.getMessage(), e);} finally {@@ -1002,7 +1006,10 @@ public final class SolrCore implements SolrInfoMBean {try {hook.preClose( this );} catch (Throwable e) {- SolrException.log(log, e);+ SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }}}}@@ -1012,6 +1019,9 @@ public final class SolrCore implements SolrInfoMBean {infoRegistry.clear();} catch (Throwable e) {SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }}try {@@ -1020,6 +1030,9 @@ public final class SolrCore implements SolrInfoMBean {}} catch (Throwable e) {SolrException.log(log,e);+ if (e instanceof Error) {+ throw (Error) e;+ }}boolean coreStateClosed = false;@@ -1033,12 +1046,18 @@ public final class SolrCore implements SolrInfoMBean {}} catch (Throwable e) {SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }}try {ExecutorUtil.shutdownAndAwaitTermination(searcherExecutor);} catch (Throwable e) {SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }}try {@@ -1052,14 +1071,20 @@ public final class SolrCore implements SolrInfoMBean {closeSearcher();} catch (Throwable e) {SolrException.log(log,e);+ if (e instanceof Error) {+ throw (Error) e;+ }}if (coreStateClosed) {try {directoryFactory.close();- } catch (Throwable t) {- SolrException.log(log, t);+ } catch (Throwable e) {+ SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }}}@@ -1071,6 +1096,9 @@ public final class SolrCore implements SolrInfoMBean {hook.postClose( this );} catch (Throwable e) {SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }}}}@@ -1646,6 +1674,9 @@ public final class SolrCore implements SolrInfoMBean {newSearcher.warm(currSearcher);} catch (Throwable e) {SolrException.log(log,e);+ if (e instanceof Error) {+ throw (Error) e;+ }}return null;}@@ -1664,6 +1695,9 @@ public final class SolrCore implements SolrInfoMBean {}} catch (Throwable e) {SolrException.log(log,null,e);+ if (e instanceof Error) {+ throw (Error) e;+ }}return null;}@@ -1682,6 +1716,9 @@ public final class SolrCore implements SolrInfoMBean {}} catch (Throwable e) {SolrException.log(log,null,e);+ if (e instanceof Error) {+ throw (Error) e;+ }}return null;}@@ -1703,6 +1740,9 @@ public final class SolrCore implements SolrInfoMBean {registerSearcher(newSearchHolder);} catch (Throwable e) {SolrException.log(log, e);+ if (e instanceof Error) {+ throw (Error) e;+ }} finally {// we are all done with the old searcher we used// for warming...@@ -1778,7 +1818,7 @@ public final class SolrCore implements SolrInfoMBean {searcherList.remove(this);}resource.close();- } catch (Throwable e) {+ } catch (Exception e) {// do not allow decref() operations to fail since they are typically called in finally blocks// and throwing another exception would be very unexpected.SolrException.log(log, "Error closing searcher:" + this, e);@@ -1826,7 +1866,7 @@ public final class SolrCore implements SolrInfoMBean {newSearcher.register(); // register subitems (caches)log.info(logid+"Registered new searcher " + newSearcher);- } catch (Throwable e) {+ } catch (Exception e) {// an exception in register() shouldn't be fatal.log(e);} finally {@@ -1871,8 +1911,8 @@ public final class SolrCore implements SolrInfoMBean {// if (req.getParams().getBool(ShardParams.IS_SHARD,false) && !(handler instanceof SearchHandler))// throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,"isShard is only acceptable with search handlers");- handler.handleRequest(req,rsp);+ handler.handleRequest(req,rsp);postDecorateResponse(handler, req, rsp);if (log.isInfoEnabled() && rsp.getToLog().size() > 0) {diff --git a/solr/core/src/java/org/apache/solr/core/SolrCores.java b/solr/core/src/java/org/apache/solr/core/SolrCores.javaindex f4a4d317564..a22c1c4f423 100644--- a/solr/core/src/java/org/apache/solr/core/SolrCores.java+++ b/solr/core/src/java/org/apache/solr/core/SolrCores.java@@ -118,8 +118,11 @@ class SolrCores {for (SolrCore core : coreList) {try {core.close();- } catch (Throwable t) {- SolrException.log(CoreContainer.log, "Error shutting down core", t);+ } catch (Throwable e) {+ SolrException.log(CoreContainer.log, "Error shutting down core", e);+ if (e instanceof Error) {+ throw (Error) e;+ }}}} while (coreList.size() > 0);diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.javaindex fe86a0b6e8d..5d6e2895426 100644--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java@@ -675,8 +675,8 @@ public class SolrResourceLoader implements ResourceLoader,Closeablefor (SolrInfoMBean bean : arr) {try {infoRegistry.put(bean.getName(), bean);- } catch (Throwable t) {- log.warn("could not register MBean '" + bean.getName() + "'.", t);+ } catch (Exception e) {+ log.warn("could not register MBean '" + bean.getName() + "'.", e);}}}diff --git a/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.javaindex bf8eac65d50..b1bc0f2c09d 100644--- a/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java@@ -253,8 +253,8 @@ public class PingRequestHandler extends RequestHandlerBase implements SolrCoreAwcore.execute(handler, req, pingrsp );ex = pingrsp.getException();}- catch( Throwable th ) {- ex = th;+ catch( Exception e ) {+ ex = e;}// Send an error or an 'OK' message (response code will be 200)diff --git a/solr/core/src/java/org/apache/solr/handler/SnapPuller.java b/solr/core/src/java/org/apache/solr/handler/SnapPuller.javaindex 26934a3ad9a..e9ee9ae24e1 100644--- a/solr/core/src/java/org/apache/solr/handler/SnapPuller.java+++ b/solr/core/src/java/org/apache/solr/handler/SnapPuller.java@@ -1356,10 +1356,10 @@ public class SnapPuller {is = new InflaterInputStream(is);}return new FastInputStream(is);- } catch (Throwable t) {+ } catch (Exception e) {//close stream on errorIOUtils.closeQuietly(is);- throw new IOException("Could not download file '" + fileName + "'", t);+ throw new IOException("Could not download file '" + fileName + "'", e);} finally {s.shutdown();}@@ -1620,10 +1620,10 @@ public class SnapPuller {is = new InflaterInputStream(is);}return new FastInputStream(is);- } catch (Throwable t) {+ } catch (Exception e) {//close stream on errorIOUtils.closeQuietly(is);- throw new IOException("Could not download file '" + fileName + "'", t);+ throw new IOException("Could not download file '" + fileName + "'", e);} finally {s.shutdown();}@@ -1683,19 +1683,13 @@ public class SnapPuller {public void destroy() {try {if (executorService != null) executorService.shutdown();- } catch (Throwable e) {- SolrException.log(LOG, e);- }- try {- abortPull();- } catch (Throwable e) {- SolrException.log(LOG, e);- }- try {- if (executorService != null) ExecutorUtil- .shutdownNowAndAwaitTermination(executorService);- } catch (Throwable e) {- SolrException.log(LOG, e);+ } finally {+ try {+ abortPull();+ } finally {+ if (executorService != null) ExecutorUtil+ .shutdownNowAndAwaitTermination(executorService);+ }}}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.javaindex 6350bce272e..83a1fc2d96d 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java@@ -766,8 +766,11 @@ public class CoreAdminHandler extends RequestHandlerBase {} catch (InterruptedException e) {Thread.currentThread().interrupt();SolrException.log(log, "", e);- } catch (Throwable t) {- SolrException.log(log, "", t);+ } catch (Throwable e) {+ SolrException.log(log, "", e);+ if (e instanceof Error) {+ throw (Error) e;+ }}core.getUpdateHandler().getSolrCoreState().doRecovery(coreContainer, core.getCoreDescriptor());@@ -1005,7 +1008,7 @@ public class CoreAdminHandler extends RequestHandlerBase {} catch (InterruptedException e) {Thread.currentThread().interrupt();log.warn("Recovery was interrupted", e);- } catch (Throwable e) {+ } catch (Exception e) {if (e instanceof SolrException)throw (SolrException)e;elsediff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.javaindex 2e36e5eef34..929b3079005 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java@@ -177,7 +177,7 @@ public class SystemInfoHandler extends RequestHandlerBaseinfo.add( "uptime", execute( "uptime" ) );}}- catch( Throwable ex ) {+ catch( Exception ex ) {ex.printStackTrace();}return info;diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.javaindex 429eb9bf7c9..c345675e4c6 100644--- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java@@ -165,7 +165,7 @@ public class HttpShardHandler extends ShardHandler {}catch( ConnectException cex ) {srsp.setException(cex); //????- } catch (Throwable th) {+ } catch (Exception th) {srsp.setException(th);if (th instanceof SolrException) {srsp.setResponseCode(((SolrException)th).code());diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.javaindex a2432cd994f..100072d14ab 100644--- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java+++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java@@ -175,25 +175,18 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.public void close() {try {ExecutorUtil.shutdownNowAndAwaitTermination(commExecutor);- } catch (Throwable e) {- SolrException.log(log, e);- }-- try {- if(defaultClient != null) {- defaultClient.getConnectionManager().shutdown();+ } finally {+ try {+ if (defaultClient != null) {+ defaultClient.getConnectionManager().shutdown();+ }+ } finally {++ if (loadbalancer != null) {+ loadbalancer.shutdown();+ }}- } catch (Throwable e) {- SolrException.log(log, e);}- try {- if(loadbalancer != null) {- loadbalancer.shutdown();- }- } catch (Throwable e) {- SolrException.log(log, e);- }-}/**diff --git a/solr/core/src/java/org/apache/solr/logging/LogWatcher.java b/solr/core/src/java/org/apache/solr/logging/LogWatcher.javaindex 2943fb3832a..280393e308b 100644--- a/solr/core/src/java/org/apache/solr/logging/LogWatcher.java+++ b/solr/core/src/java/org/apache/solr/logging/LogWatcher.java@@ -161,6 +161,9 @@ public abstract class LogWatcher<E> {}catch (Throwable e) {log.warn("Unable to read SLF4J version. LogWatcher will be disabled: " + e);+ if (e instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) e;+ }return null;}@@ -179,6 +182,9 @@ public abstract class LogWatcher<E> {}catch (Throwable e) {log.warn("Unable to load LogWatcher {}: {}", fname, e);+ if (e instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) e;+ }}return null;diff --git a/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java b/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.javaindex e371db65be3..bbea9b2f0ff 100644--- a/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java+++ b/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java@@ -64,8 +64,8 @@ public class SolrRequestInfo {for (Closeable hook : info.closeHooks) {try {hook.close();- } catch (Throwable throwable) {- SolrException.log(SolrCore.log, "Exception during close hook", throwable);+ } catch (Exception e) {+ SolrException.log(SolrCore.log, "Exception during close hook", e);}}}diff --git a/solr/core/src/java/org/apache/solr/rest/schema/BaseSchemaResource.java b/solr/core/src/java/org/apache/solr/rest/schema/BaseSchemaResource.javaindex ed7aecb06b5..705558a4ecc 100644--- a/solr/core/src/java/org/apache/solr/rest/schema/BaseSchemaResource.java+++ b/solr/core/src/java/org/apache/solr/rest/schema/BaseSchemaResource.java@@ -134,6 +134,9 @@ abstract class BaseSchemaResource extends ServerResource {}}} catch (Throwable t) {+ if (t instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) t;+ }setExisting(false);throw new ResourceException(t);}diff --git a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java b/solr/core/src/java/org/apache/solr/search/FastLRUCache.javaindex 9072da88491..d5314c31655 100644--- a/solr/core/src/java/org/apache/solr/search/FastLRUCache.java+++ b/solr/core/src/java/org/apache/solr/search/FastLRUCache.java@@ -160,7 +160,7 @@ public class FastLRUCache<K,V> extends SolrCacheBase implements SolrCache<K,V> {this, old, itemsArr[i].getKey(), itemsArr[i].getValue());if (!continueRegen) break;}- catch (Throwable e) {+ catch (Exception e) {SolrException.log(log, "Error during auto-warming of key:" + itemsArr[i].getKey(), e);}}diff --git a/solr/core/src/java/org/apache/solr/search/LFUCache.java b/solr/core/src/java/org/apache/solr/search/LFUCache.javaindex 932459d2ca0..6cf63349c4d 100644--- a/solr/core/src/java/org/apache/solr/search/LFUCache.java+++ b/solr/core/src/java/org/apache/solr/search/LFUCache.java@@ -182,7 +182,7 @@ public class LFUCache<K, V> implements SolrCache<K, V> {boolean continueRegen = regenerator.regenerateItem(searcher,this, old, itemsArr[i].getKey(), itemsArr[i].getValue());if (!continueRegen) break;- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, "Error during auto-warming of key:" + itemsArr[i].getKey(), e);}}diff --git a/solr/core/src/java/org/apache/solr/search/LRUCache.java b/solr/core/src/java/org/apache/solr/search/LRUCache.javaindex d3f9fca056e..ad1ae363a8c 100644--- a/solr/core/src/java/org/apache/solr/search/LRUCache.java+++ b/solr/core/src/java/org/apache/solr/search/LRUCache.java@@ -188,7 +188,7 @@ public class LRUCache<K,V> extends SolrCacheBase implements SolrCache<K,V> {boolean continueRegen = regenerator.regenerateItem(searcher, this, old, keys[i], vals[i]);if (!continueRegen) break;}- catch (Throwable e) {+ catch (Exception e) {SolrException.log(log,"Error during auto-warming of key:" + keys[i], e);}}diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.javaindex 8689bcfe395..d8f41715b60 100644--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java@@ -175,9 +175,9 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInDirectory dir = directoryFactory.get(path, DirContext.DEFAULT, config.lockType);try {reader = core.getIndexReaderFactory().newReader(dir, core);- } catch (Throwable t) {+ } catch (Exception e) {directoryFactory.release(dir);- throw new SolrException(ErrorCode.SERVER_ERROR, "Error opening Reader", t);+ throw new SolrException(ErrorCode.SERVER_ERROR, "Error opening Reader", e);}return reader;}@@ -347,8 +347,8 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInlong cpg = reader.getIndexCommit().getGeneration();try {if (closeReader) reader.decRef();- } catch (Throwable t) {- SolrException.log(log, "Problem dec ref'ing reader", t);+ } catch (Exception e) {+ SolrException.log(log, "Problem dec ref'ing reader", e);}if (directoryFactory.searchersReserveCommitPoints()) {diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.javaindex 01b23eae3c0..6558c41d3ae 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java@@ -136,6 +136,9 @@ public class SolrDispatchFilter implements Filter// catch this so our filter still workslog.error( "Could not start Solr. Check solr/home property and the logs");SolrCore.log( t );+ if (t instanceof Error) {+ throw (Error) t;+ }}log.info("SolrDispatchFilter.init() done");@@ -434,17 +437,25 @@ public class SolrDispatchFilter implements Filter}catch (Throwable ex) {sendError( core, solrReq, request, (HttpServletResponse)response, ex );- return;- }- finally {- if( solrReq != null ) {- log.debug("Closing out SolrRequest: {}", solrReq);- solrReq.close();+ if (ex instanceof Error) {+ throw (Error) ex;}- if (core != null) {- core.close();+ return;+ } finally {+ try {+ if (solrReq != null) {+ log.debug("Closing out SolrRequest: {}", solrReq);+ solrReq.close();+ }+ } finally {+ try {+ if (core != null) {+ core.close();+ }+ } finally {+ SolrRequestInfo.clearRequestInfo();+ }}- SolrRequestInfo.clearRequestInfo();}}@@ -758,6 +769,7 @@ public class SolrDispatchFilter implements FilterServletRequest request,HttpServletResponse response,Throwable ex) throws IOException {+ Exception exp = null;SolrCore localCore = null;try {SolrQueryResponse solrResp = new SolrQueryResponse();@@ -786,15 +798,21 @@ public class SolrDispatchFilter implements FilterQueryResponseWriter writer = core.getQueryResponseWriter(req);writeResponse(solrResp, response, writer, req, Method.GET);}- catch( Throwable t ) { // This error really does not matter- SimpleOrderedMap info = new SimpleOrderedMap();- int code = ResponseUtils.getErrorInfo(ex, info, log);- response.sendError( code, info.toString() );+ catch (Exception e) { // This error really does not matter+ exp = e;} finally {- if (core == null && localCore != null) {- localCore.close();+ try {+ if (exp != null) {+ SimpleOrderedMap info = new SimpleOrderedMap();+ int code = ResponseUtils.getErrorInfo(ex, info, log);+ response.sendError(code, info.toString());+ }+ } finally {+ if (core == null && localCore != null) {+ localCore.close();+ }}- }+ }}//---------------------------------------------------------------------diff --git a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.javaindex ef0a2a98287..9dd0d526a2d 100644--- a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java+++ b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java@@ -71,8 +71,8 @@ public final class DefaultSolrCoreState extends SolrCoreState implements RecoverindexWriter.close();}indexWriter = null;- } catch (Throwable t) {- log.error("Error during shutdown of writer.", t);+ } catch (Exception e) {+ log.error("Error during shutdown of writer.", e);}}@@ -162,17 +162,17 @@ public final class DefaultSolrCoreState extends SolrCoreState implements Recovertry {log.info("Closing old IndexWriter... core=" + coreName);indexWriter.close();- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log, "Error closing old IndexWriter. core="- + coreName, t);+ + coreName, e);}} else {try {log.info("Rollback old IndexWriter... core=" + coreName);indexWriter.rollback();- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log, "Error rolling back old IndexWriter. core="- + coreName, t);+ + coreName, e);}}}@@ -220,17 +220,17 @@ public final class DefaultSolrCoreState extends SolrCoreState implements Recovertry {log.info("Closing old IndexWriter... core=" + coreName);indexWriter.close();- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log, "Error closing old IndexWriter. core="- + coreName, t);+ + coreName, e);}} else {try {log.info("Rollback old IndexWriter... core=" + coreName);indexWriter.rollback();- } catch (Throwable t) {+ } catch (Exception e) {SolrException.log(log, "Error rolling back old IndexWriter. core="- + coreName, t);+ + coreName, e);}}}diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.javaindex ea9ea298353..336844014ae 100644--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java@@ -751,6 +751,9 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState}} catch (Throwable th) {log.error("Error in final commit", th);+ if (th instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) th;+ }}// we went through the normal process to commit, so we don't have to artificially@@ -759,6 +762,9 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreStateif (ulog != null) ulog.close(false);} catch (Throwable th) {log.error("Error closing log files", th);+ if (th instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) th;+ }}if (writer != null) writer.close();diff --git a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java b/solr/core/src/java/org/apache/solr/update/SolrCoreState.javaindex 5464d2894a4..649b1f65140 100644--- a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java+++ b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java@@ -70,8 +70,8 @@ public abstract class SolrCoreState {try {log.info("Closing SolrCoreState");close(closer);- } catch (Throwable t) {- log.error("Error closing SolrCoreState", t);+ } catch (Exception e) {+ log.error("Error closing SolrCoreState", e);}}return close;diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java b/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.javaindex 736893d781c..a9948327d92 100644--- a/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java+++ b/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java@@ -134,14 +134,17 @@ public class SolrIndexWriter extends IndexWriter {// don't allow interruptioncontinue;} catch (Throwable t) {+ if (t instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) t;+ }log.error("Error closing IndexWriter, trying rollback", t);super.rollback();}if (IndexWriter.isLocked(directory)) {try {IndexWriter.unlock(directory);- } catch (Throwable t) {- log.error("Coud not unlock directory after seemingly failed IndexWriter#close()", t);+ } catch (Exception e) {+ log.error("Coud not unlock directory after seemingly failed IndexWriter#close()", e);}}break;diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.javaindex edead5a001d..7353bfa3e74 100644--- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java+++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java@@ -421,7 +421,7 @@ public class UpdateLog implements PluginInfoInitialized {try {RefCounted<SolrIndexSearcher> holder = uhandler.core.openNewSearcher(true, true);holder.decref();- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, "Error opening realtime searcher for deleteByQuery", e);}@@ -491,7 +491,7 @@ public class UpdateLog implements PluginInfoInitialized {try {RefCounted<SolrIndexSearcher> holder = uhandler.core.openNewSearcher(true, true);holder.decref();- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, "Error opening realtime searcher for deleteByQuery", e);}@@ -512,7 +512,7 @@ public class UpdateLog implements PluginInfoInitialized {try {RefCounted<SolrIndexSearcher> holder = uhandler.core.openNewSearcher(true, true);holder.decref();- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, "Error opening realtime searcher for deleteByQuery", e);}@@ -859,7 +859,7 @@ public class UpdateLog implements PluginInfoInitialized {synchronized (this) {try {ExecutorUtil.shutdownNowAndAwaitTermination(recoveryExecutor);- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, e);}@@ -1222,7 +1222,7 @@ public class UpdateLog implements PluginInfoInitialized {recoveryInfo.errors++;SolrException.log(log, e);}- } catch (Throwable e) {+ } catch (Exception e) {recoveryInfo.errors++;SolrException.log(log, e);} finally {@@ -1295,7 +1295,7 @@ public class UpdateLog implements PluginInfoInitialized {SolrException.log(log,e);} catch (IOException e) {SolrException.log(log,e);- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log,e);}@@ -1381,7 +1381,7 @@ public class UpdateLog implements PluginInfoInitialized {recoveryInfo.errors++;loglog.warn("REYPLAY_ERR: IOException reading log", ex);// could be caused by an incomplete flush if recovering from log- } catch (Throwable ex) {+ } catch (Exception ex) {recoveryInfo.errors++;loglog.warn("REPLAY_ERR: Exception replaying log", ex);// something wrong with the request?diff --git a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.javaindex c72bae38cb2..ae5d5c8ca8a 100644--- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java+++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java@@ -73,7 +73,7 @@ public class UpdateShardHandler {public void close() {try {ExecutorUtil.shutdownAndAwaitTermination(updateExecutor);- } catch (Throwable e) {+ } catch (Exception e) {SolrException.log(log, e);} finally {clientConnectionManager.shutdown();diff --git a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.javaindex c2224098e46..8a044a5afd5 100644--- a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java@@ -184,23 +184,23 @@ public class ChaosMonkeyShardSplitTest extends ShardSplitTest {Thread.sleep(800);overseerClient.close();overseerClient = electNewOverseer(zkAddress);- } catch (Throwable e) {+ } catch (Exception e) {// e.printStackTrace();}}try {Thread.sleep(100);- } catch (Throwable e) {+ } catch (Exception e) {// e.printStackTrace();}}- } catch (Throwable t) {+ } catch (Exception t) {// ignore} finally {if (overseerClient != null) {try {overseerClient.close();- } catch (Throwable t) {+ } catch (Exception t) {// ignore}}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.javaindex 91332488056..86e44781fc7 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java@@ -250,6 +250,9 @@ public class ConcurrentUpdateSolrServer extends SolrServer {}}} catch (Throwable e) {+ if (e instanceof OutOfMemoryError) {+ throw (OutOfMemoryError) e;+ }handleError(e);} finally {diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.javaindex 11b680ff4c3..7a76f7a4e6c 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java@@ -510,9 +510,12 @@ public class HttpSolrServer extends SolrServer {if (respBody != null && shouldClose) {try {respBody.close();- } catch (Throwable t) {} // ignore- if (!success) {- method.abort();+ } catch (IOException e) {+ log.error("", e);+ } finally {+ if (!success) {+ method.abort();+ }}}}diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.javaindex e4267c73688..cf9cd5f2f1d 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java@@ -146,7 +146,7 @@ public class ConnectionManager implements Watcher {Thread.currentThread().interrupt();// we must have been asked to stopthrow new RuntimeException(e);- } catch (Throwable t) {+ } catch (Exception t) {closeKeeper(keeper);throw new RuntimeException(t);}diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.javaindex 093809ba6f5..fcd9be1c4a5 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java@@ -123,7 +123,7 @@ public class SolrZkClient {}}});- } catch (Throwable e) {+ } catch (Exception e) {connManager.close();if (keeper != null) {try {@@ -137,7 +137,7 @@ public class SolrZkClient {try {connManager.waitForConnected(clientConnectTimeout);- } catch (Throwable e) {+ } catch (Exception e) {connManager.close();try {keeper.close();diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.javaindex 2a6eb37f767..c1465b8e93d 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java@@ -43,8 +43,8 @@ public abstract class ZkClientConnectionStrategy {for (DisconnectedListener listener : disconnectedListeners) {try {listener.disconnected();- } catch (Throwable t) {- SolrException.log(log, "", t);+ } catch (Exception e) {+ SolrException.log(log, "", e);}}}@@ -53,8 +53,8 @@ public abstract class ZkClientConnectionStrategy {for (ConnectedListener listener : connectedListeners) {try {listener.connected();- } catch (Throwable t) {- SolrException.log(log, "", t);+ } catch (Exception e) {+ SolrException.log(log, "", e);}}}