diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java index 85a56817f..04f09c040 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java @@ -362,7 +362,11 @@ public Observable toObservable() { /* mark that we received this response from cache */ metrics.markResponseFromCache(); isExecutionComplete.set(true); - executionHook.onCacheHit(this); + try { + executionHook.onCacheHit(this); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onCacheHit", hookEx); + } return new CachedObservableResponse((CachedObservableOriginal) fromCache, this); } } @@ -379,7 +383,11 @@ public void call(Subscriber observer) { metrics.incrementConcurrentExecutionCount(); // mark that we're starting execution on the ExecutionHook - executionHook.onStart(_this); + try { + executionHook.onStart(_this); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onStart", hookEx); + } /* determine if we're allowed to execute */ if (circuitBreaker.allowRequest()) { @@ -511,9 +519,21 @@ public void call(Subscriber s) { s.onError(new RuntimeException("timed out before executing run()")); } else { // not timed out so execute - executionHook.onThreadStart(_self); - executionHook.onRunStart(_self); - executionHook.onExecutionStart(_self); + try { + executionHook.onThreadStart(_self); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onThreadStart", hookEx); + } + try { + executionHook.onRunStart(_self); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onRunStart", hookEx); + } + try { + executionHook.onExecutionStart(_self); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onExecutionStart", hookEx); + } threadPool.markThreadExecution(); // store the command that is being run endCurrentThreadExecutingCommand.set(Hystrix.startCurrentThreadExecutingCommand(getCommandKey())); @@ -530,8 +550,16 @@ public Boolean call() { })); } else { // semaphore isolated - executionHook.onRunStart(_self); - executionHook.onExecutionStart(_self); + try { + executionHook.onRunStart(_self); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onRunStart", hookEx); + } + try { + executionHook.onExecutionStart(_self); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onExecutionStart", hookEx); + } // store the command that is being run endCurrentThreadExecutingCommand.set(Hystrix.startCurrentThreadExecutingCommand(getCommandKey())); run = getExecutionObservableWithLifecycle(); //the getExecutionObservableWithLifecycle method already wraps sync exceptions, so no need to catch here @@ -603,8 +631,8 @@ public Observable call(Throwable t) { } else { logger.warn("ExecutionHook.onError returned an exception that was not an instance of HystrixBadRequestException so will be ignored.", decorated); } - } catch (Exception hookException) { - logger.warn("Error calling ExecutionHook.onError", hookException); + } catch (Exception hookEx) { + logger.warn("Error calling ExecutionHook.onError", hookEx); } /* * HystrixBadRequestException is treated differently and allowed to propagate without any stats tracking or fallback logic @@ -665,7 +693,7 @@ private Observable getExecutionObservableWithLifecycle() { // so we catch it here and turn it into Observable.error userObservable = Observable.error(ex); } - return userObservable .lift(new ExecutionHookApplication(_self)) + return userObservable.lift(new ExecutionHookApplication(_self)) .lift(new DeprecatedOnRunHookApplication(_self)) .doOnTerminate(new Action0() { @Override @@ -725,7 +753,11 @@ private Observable getFallbackOrThrowException(final HystrixEventType eventTy // acquire a permit if (fallbackSemaphore.tryAcquire()) { if (isFallbackUserSupplied(this)) { - executionHook.onFallbackStart(this); + try { + executionHook.onFallbackStart(this); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onFallbackStart", hookEx); + } } try { @@ -883,7 +915,11 @@ protected void handleThreadEnd() { } if (isExecutedInThread.get()) { threadPool.markThreadCompletion(); - executionHook.onThreadComplete(this); + try { + executionHook.onThreadComplete(this); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onThreadComplete", hookEx); + } } } @@ -1297,7 +1333,11 @@ public Subscriber call(final Subscriber subscriber) { return new Subscriber(subscriber) { @Override public void onCompleted() { - executionHook.onSuccess(cmd); + try { + executionHook.onSuccess(cmd); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onSuccess", hookEx); + } subscriber.onCompleted(); } @@ -1328,7 +1368,11 @@ public Subscriber call(final Subscriber subscriber) { return new Subscriber(subscriber) { @Override public void onCompleted() { - executionHook.onExecutionSuccess(cmd); + try { + executionHook.onExecutionSuccess(cmd); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onExecutionSuccess", hookEx); + } subscriber.onCompleted(); } @@ -1359,7 +1403,11 @@ public Subscriber call(final Subscriber subscriber) { return new Subscriber(subscriber) { @Override public void onCompleted() { - executionHook.onFallbackSuccess(cmd); + try { + executionHook.onFallbackSuccess(cmd); + } catch (Throwable hookEx) { + logger.warn("Error calling HystrixCommandExecutionHook.onFallbackSuccess", hookEx); + } subscriber.onCompleted(); } @@ -1405,7 +1453,7 @@ public void onNext(R r) { R wrappedValue = executionHook.onComplete(cmd, r); subscriber.onNext(wrappedValue); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onComplete", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onComplete", hookEx); subscriber.onNext(r); } } @@ -1437,7 +1485,7 @@ public void onError(Throwable t) { Exception wrappedEx = executionHook.onRunError(cmd, e); subscriber.onError(wrappedEx); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onRunError", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onRunError", hookEx); subscriber.onError(e); } } @@ -1448,7 +1496,7 @@ public void onNext(R r) { R wrappedValue = executionHook.onRunSuccess(cmd, r); subscriber.onNext(wrappedValue); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onRunSuccess", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onRunSuccess", hookEx); subscriber.onNext(r); } } @@ -1485,7 +1533,7 @@ public void onNext(R r) { R wrappedValue = executionHook.onFallbackSuccess(cmd, r); subscriber.onNext(wrappedValue); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onFallbackSuccess", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onFallbackSuccess", hookEx); subscriber.onNext(r); } } @@ -1498,7 +1546,7 @@ private Exception wrapWithOnExecutionErrorHook(Throwable t) { try { return executionHook.onExecutionError(this, e); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onExecutionError", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onExecutionError", hookEx); return e; } } @@ -1512,7 +1560,7 @@ private Exception wrapWithOnFallbackErrorHook(Throwable t) { return e; } } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onFallbackError", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onFallbackError", hookEx); return e; } } @@ -1522,7 +1570,7 @@ private Exception wrapWithOnErrorHook(FailureType failureType, Throwable t) { try { return executionHook.onError(this, failureType, e); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onError", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onError", hookEx); return e; } } @@ -1531,7 +1579,7 @@ private R wrapWithOnExecutionEmitHook(R r) { try { return executionHook.onExecutionEmit(this, r); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onExecutionEmit", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onExecutionEmit", hookEx); return r; } } @@ -1540,7 +1588,7 @@ private R wrapWithOnFallbackEmitHook(R r) { try { return executionHook.onFallbackEmit(this, r); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onFallbackEmit", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onFallbackEmit", hookEx); return r; } } @@ -1549,7 +1597,7 @@ private R wrapWithOnEmitHook(R r) { try { return executionHook.onEmit(this, r); } catch (Throwable hookEx) { - logger.warn("Error calling ExecutionHook.onEmit", hookEx); + logger.warn("Error calling HystrixCommandExecutionHook.onEmit", hookEx); return r; } }