You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by va...@apache.org on 2019/05/20 08:59:00 UTC
[camel] branch camel-2.x updated: CAMEL-13541: fixed Race condition
in camel-hystrix when xecutionTimeoutInMilliseconds() and onFallback() are
used
This is an automated email from the ASF dual-hosted git repository.
valdar pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.x by this push:
new faf5ad3 CAMEL-13541: fixed Race condition in camel-hystrix when xecutionTimeoutInMilliseconds() and onFallback() are used
faf5ad3 is described below
commit faf5ad3ad244e64710c9df56729e9d3d62292f6c
Author: Andrea Tarocchi <at...@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