This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.22.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3fab83328703f944115a81cb1ae5a371e7d52d62 Author: Andrea Tarocchi <ataro...@redhat.com> AuthorDate: Fri May 17 22:32:09 2019 +0200 CAMEL-13541: fixed Race condition in camel-hystrix when xecutionTimeoutInMilliseconds() and onFallback() are used --- .../component/hystrix/processor/HystrixProcessorCommand.java | 10 +++++++++- .../camel/component/hystrix/processor/HystrixTimeoutTest.java | 4 ++-- .../hystrix/processor/HystrixTimeoutWithFallbackTest.java | 9 ++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java index 9275285..e2e58c8 100644 --- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java +++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java @@ -117,6 +117,15 @@ public class HystrixProcessorCommand extends HystrixCommand { copy.setException(e); } + // if hystrix execution timeout is enabled and fallback is enabled and a timeout occurs + // then a hystrix timer thread executes the fallback so we can stop run() execution + if(getProperties().executionTimeoutEnabled().get() + && getProperties().fallbackEnabled().get() + && isCommandTimedOut.get() == TimedOutStatus.TIMED_OUT) { + LOG.debug("Exiting run command due to a hystrix execution timeout in processing exchange: {}", exchange); + return null; + } + // when a hystrix timeout occurs then a hystrix timer thread executes the fallback // and therefore we need this thread to not do anymore if fallback is already in process if (fallbackInUse.get()) { @@ -129,7 +138,6 @@ public class HystrixProcessorCommand extends HystrixCommand { Exception camelExchangeException = copy.getException(); synchronized (lock) { - // when a hystrix timeout occurs then a hystrix timer thread executes the fallback // and therefore we need this thread to not do anymore if fallback is already in process if (fallbackInUse.get()) { diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutTest.java index b36203c..00568b8 100644 --- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutTest.java +++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutTest.java @@ -40,7 +40,7 @@ public class HystrixTimeoutTest extends CamelTestSupport { // this calls the slow route and therefore causes a timeout which triggers an exception try { template.requestBody("direct:start", "slow"); - fail("Should fail due timeout"); + fail("Should fail due to timeout"); } catch (Exception e) { // expected a timeout assertIsInstanceOf(TimeoutException.class, e.getCause().getCause()); @@ -54,7 +54,7 @@ public class HystrixTimeoutTest extends CamelTestSupport { try { log.info(">>> test run " + i + " <<<"); template.requestBody("direct:start", "slow"); - fail("Should fail due timeout"); + fail("Should fail due to timeout"); } catch (Exception e) { // expected a timeout assertIsInstanceOf(TimeoutException.class, e.getCause().getCause()); diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutWithFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutWithFallbackTest.java index 27790bb..a66b2ae 100644 --- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutWithFallbackTest.java +++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixTimeoutWithFallbackTest.java @@ -30,14 +30,14 @@ public class HystrixTimeoutWithFallbackTest extends CamelTestSupport { public void testFast() throws Exception { // this calls the fast route and therefore we get a response Object out = template.requestBody("direct:start", "fast"); - assertEquals("Fast response", out); + assertEquals("LAST CHANGE", out); } @Test public void testSlow() throws Exception { // this calls the slow route and therefore causes a timeout which triggers the fallback Object out = template.requestBody("direct:start", "slow"); - assertEquals("Fallback response", out); + assertEquals("LAST CHANGE", out); } @Override @@ -58,7 +58,10 @@ public class HystrixTimeoutWithFallbackTest extends CamelTestSupport { .transform().constant("Fallback response") .log("Hystrix fallback end: ${threadName}") .end() - .log("After Hystrix ${body}"); + .log("After Hystrix ${body}") + .transform(simple("A CHANGE")) + .transform(simple("LAST CHANGE")) + .log("End ${body}"); from("direct:fast") // this is a fast route and takes 1 second to respond