@@ -362,7 +362,11 @@ public Observable<R> toObservable() {
362
362
/* mark that we received this response from cache */
363
363
metrics .markResponseFromCache ();
364
364
isExecutionComplete .set (true );
365
- executionHook .onCacheHit (this );
365
+ try {
366
+ executionHook .onCacheHit (this );
367
+ } catch (Throwable hookEx ) {
368
+ logger .warn ("Error calling HystrixCommandExecutionHook.onCacheHit" , hookEx );
369
+ }
366
370
return new CachedObservableResponse <R >((CachedObservableOriginal <R >) fromCache , this );
367
371
}
368
372
}
@@ -379,7 +383,11 @@ public void call(Subscriber<? super R> observer) {
379
383
metrics .incrementConcurrentExecutionCount ();
380
384
381
385
// mark that we're starting execution on the ExecutionHook
382
- executionHook .onStart (_this );
386
+ try {
387
+ executionHook .onStart (_this );
388
+ } catch (Throwable hookEx ) {
389
+ logger .warn ("Error calling HystrixCommandExecutionHook.onStart" , hookEx );
390
+ }
383
391
384
392
/* determine if we're allowed to execute */
385
393
if (circuitBreaker .allowRequest ()) {
@@ -511,9 +519,21 @@ public void call(Subscriber<? super R> s) {
511
519
s .onError (new RuntimeException ("timed out before executing run()" ));
512
520
} else {
513
521
// not timed out so execute
514
- executionHook .onThreadStart (_self );
515
- executionHook .onRunStart (_self );
516
- executionHook .onExecutionStart (_self );
522
+ try {
523
+ executionHook .onThreadStart (_self );
524
+ } catch (Throwable hookEx ) {
525
+ logger .warn ("Error calling HystrixCommandExecutionHook.onThreadStart" , hookEx );
526
+ }
527
+ try {
528
+ executionHook .onRunStart (_self );
529
+ } catch (Throwable hookEx ) {
530
+ logger .warn ("Error calling HystrixCommandExecutionHook.onRunStart" , hookEx );
531
+ }
532
+ try {
533
+ executionHook .onExecutionStart (_self );
534
+ } catch (Throwable hookEx ) {
535
+ logger .warn ("Error calling HystrixCommandExecutionHook.onExecutionStart" , hookEx );
536
+ }
517
537
threadPool .markThreadExecution ();
518
538
// store the command that is being run
519
539
endCurrentThreadExecutingCommand .set (Hystrix .startCurrentThreadExecutingCommand (getCommandKey ()));
@@ -530,8 +550,16 @@ public Boolean call() {
530
550
}));
531
551
} else {
532
552
// semaphore isolated
533
- executionHook .onRunStart (_self );
534
- executionHook .onExecutionStart (_self );
553
+ try {
554
+ executionHook .onRunStart (_self );
555
+ } catch (Throwable hookEx ) {
556
+ logger .warn ("Error calling HystrixCommandExecutionHook.onRunStart" , hookEx );
557
+ }
558
+ try {
559
+ executionHook .onExecutionStart (_self );
560
+ } catch (Throwable hookEx ) {
561
+ logger .warn ("Error calling HystrixCommandExecutionHook.onExecutionStart" , hookEx );
562
+ }
535
563
// store the command that is being run
536
564
endCurrentThreadExecutingCommand .set (Hystrix .startCurrentThreadExecutingCommand (getCommandKey ()));
537
565
run = getExecutionObservableWithLifecycle (); //the getExecutionObservableWithLifecycle method already wraps sync exceptions, so no need to catch here
@@ -603,8 +631,8 @@ public Observable<R> call(Throwable t) {
603
631
} else {
604
632
logger .warn ("ExecutionHook.onError returned an exception that was not an instance of HystrixBadRequestException so will be ignored." , decorated );
605
633
}
606
- } catch (Exception hookException ) {
607
- logger .warn ("Error calling ExecutionHook.onError" , hookException );
634
+ } catch (Exception hookEx ) {
635
+ logger .warn ("Error calling ExecutionHook.onError" , hookEx );
608
636
}
609
637
/*
610
638
* HystrixBadRequestException is treated differently and allowed to propagate without any stats tracking or fallback logic
@@ -665,7 +693,7 @@ private Observable<R> getExecutionObservableWithLifecycle() {
665
693
// so we catch it here and turn it into Observable.error
666
694
userObservable = Observable .error (ex );
667
695
}
668
- return userObservable .lift (new ExecutionHookApplication (_self ))
696
+ return userObservable .lift (new ExecutionHookApplication (_self ))
669
697
.lift (new DeprecatedOnRunHookApplication (_self ))
670
698
.doOnTerminate (new Action0 () {
671
699
@ Override
@@ -725,7 +753,11 @@ private Observable<R> getFallbackOrThrowException(final HystrixEventType eventTy
725
753
// acquire a permit
726
754
if (fallbackSemaphore .tryAcquire ()) {
727
755
if (isFallbackUserSupplied (this )) {
728
- executionHook .onFallbackStart (this );
756
+ try {
757
+ executionHook .onFallbackStart (this );
758
+ } catch (Throwable hookEx ) {
759
+ logger .warn ("Error calling HystrixCommandExecutionHook.onFallbackStart" , hookEx );
760
+ }
729
761
}
730
762
731
763
try {
@@ -883,7 +915,11 @@ protected void handleThreadEnd() {
883
915
}
884
916
if (isExecutedInThread .get ()) {
885
917
threadPool .markThreadCompletion ();
886
- executionHook .onThreadComplete (this );
918
+ try {
919
+ executionHook .onThreadComplete (this );
920
+ } catch (Throwable hookEx ) {
921
+ logger .warn ("Error calling HystrixCommandExecutionHook.onThreadComplete" , hookEx );
922
+ }
887
923
}
888
924
}
889
925
@@ -1297,7 +1333,11 @@ public Subscriber<? super R> call(final Subscriber<? super R> subscriber) {
1297
1333
return new Subscriber <R >(subscriber ) {
1298
1334
@ Override
1299
1335
public void onCompleted () {
1300
- executionHook .onSuccess (cmd );
1336
+ try {
1337
+ executionHook .onSuccess (cmd );
1338
+ } catch (Throwable hookEx ) {
1339
+ logger .warn ("Error calling HystrixCommandExecutionHook.onSuccess" , hookEx );
1340
+ }
1301
1341
subscriber .onCompleted ();
1302
1342
}
1303
1343
@@ -1328,7 +1368,11 @@ public Subscriber<? super R> call(final Subscriber<? super R> subscriber) {
1328
1368
return new Subscriber <R >(subscriber ) {
1329
1369
@ Override
1330
1370
public void onCompleted () {
1331
- executionHook .onExecutionSuccess (cmd );
1371
+ try {
1372
+ executionHook .onExecutionSuccess (cmd );
1373
+ } catch (Throwable hookEx ) {
1374
+ logger .warn ("Error calling HystrixCommandExecutionHook.onExecutionSuccess" , hookEx );
1375
+ }
1332
1376
subscriber .onCompleted ();
1333
1377
}
1334
1378
@@ -1359,7 +1403,11 @@ public Subscriber<? super R> call(final Subscriber<? super R> subscriber) {
1359
1403
return new Subscriber <R >(subscriber ) {
1360
1404
@ Override
1361
1405
public void onCompleted () {
1362
- executionHook .onFallbackSuccess (cmd );
1406
+ try {
1407
+ executionHook .onFallbackSuccess (cmd );
1408
+ } catch (Throwable hookEx ) {
1409
+ logger .warn ("Error calling HystrixCommandExecutionHook.onFallbackSuccess" , hookEx );
1410
+ }
1363
1411
subscriber .onCompleted ();
1364
1412
}
1365
1413
@@ -1405,7 +1453,7 @@ public void onNext(R r) {
1405
1453
R wrappedValue = executionHook .onComplete (cmd , r );
1406
1454
subscriber .onNext (wrappedValue );
1407
1455
} catch (Throwable hookEx ) {
1408
- logger .warn ("Error calling ExecutionHook .onComplete" , hookEx );
1456
+ logger .warn ("Error calling HystrixCommandExecutionHook .onComplete" , hookEx );
1409
1457
subscriber .onNext (r );
1410
1458
}
1411
1459
}
@@ -1437,7 +1485,7 @@ public void onError(Throwable t) {
1437
1485
Exception wrappedEx = executionHook .onRunError (cmd , e );
1438
1486
subscriber .onError (wrappedEx );
1439
1487
} catch (Throwable hookEx ) {
1440
- logger .warn ("Error calling ExecutionHook .onRunError" , hookEx );
1488
+ logger .warn ("Error calling HystrixCommandExecutionHook .onRunError" , hookEx );
1441
1489
subscriber .onError (e );
1442
1490
}
1443
1491
}
@@ -1448,7 +1496,7 @@ public void onNext(R r) {
1448
1496
R wrappedValue = executionHook .onRunSuccess (cmd , r );
1449
1497
subscriber .onNext (wrappedValue );
1450
1498
} catch (Throwable hookEx ) {
1451
- logger .warn ("Error calling ExecutionHook .onRunSuccess" , hookEx );
1499
+ logger .warn ("Error calling HystrixCommandExecutionHook .onRunSuccess" , hookEx );
1452
1500
subscriber .onNext (r );
1453
1501
}
1454
1502
}
@@ -1485,7 +1533,7 @@ public void onNext(R r) {
1485
1533
R wrappedValue = executionHook .onFallbackSuccess (cmd , r );
1486
1534
subscriber .onNext (wrappedValue );
1487
1535
} catch (Throwable hookEx ) {
1488
- logger .warn ("Error calling ExecutionHook .onFallbackSuccess" , hookEx );
1536
+ logger .warn ("Error calling HystrixCommandExecutionHook .onFallbackSuccess" , hookEx );
1489
1537
subscriber .onNext (r );
1490
1538
}
1491
1539
}
@@ -1498,7 +1546,7 @@ private Exception wrapWithOnExecutionErrorHook(Throwable t) {
1498
1546
try {
1499
1547
return executionHook .onExecutionError (this , e );
1500
1548
} catch (Throwable hookEx ) {
1501
- logger .warn ("Error calling ExecutionHook .onExecutionError" , hookEx );
1549
+ logger .warn ("Error calling HystrixCommandExecutionHook .onExecutionError" , hookEx );
1502
1550
return e ;
1503
1551
}
1504
1552
}
@@ -1512,7 +1560,7 @@ private Exception wrapWithOnFallbackErrorHook(Throwable t) {
1512
1560
return e ;
1513
1561
}
1514
1562
} catch (Throwable hookEx ) {
1515
- logger .warn ("Error calling ExecutionHook .onFallbackError" , hookEx );
1563
+ logger .warn ("Error calling HystrixCommandExecutionHook .onFallbackError" , hookEx );
1516
1564
return e ;
1517
1565
}
1518
1566
}
@@ -1522,7 +1570,7 @@ private Exception wrapWithOnErrorHook(FailureType failureType, Throwable t) {
1522
1570
try {
1523
1571
return executionHook .onError (this , failureType , e );
1524
1572
} catch (Throwable hookEx ) {
1525
- logger .warn ("Error calling ExecutionHook .onError" , hookEx );
1573
+ logger .warn ("Error calling HystrixCommandExecutionHook .onError" , hookEx );
1526
1574
return e ;
1527
1575
}
1528
1576
}
@@ -1531,7 +1579,7 @@ private R wrapWithOnExecutionEmitHook(R r) {
1531
1579
try {
1532
1580
return executionHook .onExecutionEmit (this , r );
1533
1581
} catch (Throwable hookEx ) {
1534
- logger .warn ("Error calling ExecutionHook .onExecutionEmit" , hookEx );
1582
+ logger .warn ("Error calling HystrixCommandExecutionHook .onExecutionEmit" , hookEx );
1535
1583
return r ;
1536
1584
}
1537
1585
}
@@ -1540,7 +1588,7 @@ private R wrapWithOnFallbackEmitHook(R r) {
1540
1588
try {
1541
1589
return executionHook .onFallbackEmit (this , r );
1542
1590
} catch (Throwable hookEx ) {
1543
- logger .warn ("Error calling ExecutionHook .onFallbackEmit" , hookEx );
1591
+ logger .warn ("Error calling HystrixCommandExecutionHook .onFallbackEmit" , hookEx );
1544
1592
return r ;
1545
1593
}
1546
1594
}
@@ -1549,7 +1597,7 @@ private R wrapWithOnEmitHook(R r) {
1549
1597
try {
1550
1598
return executionHook .onEmit (this , r );
1551
1599
} catch (Throwable hookEx ) {
1552
- logger .warn ("Error calling ExecutionHook .onEmit" , hookEx );
1600
+ logger .warn ("Error calling HystrixCommandExecutionHook .onEmit" , hookEx );
1553
1601
return r ;
1554
1602
}
1555
1603
}
0 commit comments