CAMEL-8004: Fixed concurreny dead-lock potential when using getRoutes from CamelContext. Thanks to Babak for researching this.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/62af8b8a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/62af8b8a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/62af8b8a Branch: refs/heads/camel-2.13.x Commit: 62af8b8a98c9be975dd505e161217eeb1fd63b46 Parents: f129e29 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Nov 7 14:17:38 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Nov 7 14:42:43 2014 +0100 ---------------------------------------------------------------------- .../apache/camel/impl/DefaultCamelContext.java | 18 ++++++++++++------ .../camel/component/quartz2/QuartzEndpoint.java | 2 +- .../quartz2/QuartzNameCollisionTest.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/62af8b8a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 865c1ef..8580ae4 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -644,12 +644,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon return routeStartupOrder; } - public synchronized List<Route> getRoutes() { + public List<Route> getRoutes() { // lets return a copy of the collection as objects are removed later when services are stopped if (routes.isEmpty()) { return Collections.emptyList(); } else { - return new ArrayList<Route>(routes); + synchronized (routes) { + return new ArrayList<Route>(routes); + } } } @@ -667,12 +669,16 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon throw new UnsupportedOperationException("Overriding existing routes is not supported yet, use addRouteCollection instead"); } - synchronized void removeRouteCollection(Collection<Route> routes) { - this.routes.removeAll(routes); + void removeRouteCollection(Collection<Route> routes) { + synchronized (routes) { + this.routes.removeAll(routes); + } } - synchronized void addRouteCollection(Collection<Route> routes) throws Exception { - this.routes.addAll(routes); + void addRouteCollection(Collection<Route> routes) throws Exception { + synchronized (routes) { + this.routes.addAll(routes); + } } public void addRoutes(RoutesBuilder builder) throws Exception { http://git-wip-us.apache.org/repos/asf/camel/blob/62af8b8a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java index 1aeb9d0..2166820 100644 --- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java +++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java @@ -257,7 +257,7 @@ public class QuartzEndpoint extends DefaultEndpoint { QuartzEndpoint quartzEndpoint = (QuartzEndpoint) route.getEndpoint(); TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey(); if (triggerKey.equals(checkTriggerKey)) { - throw new IllegalArgumentException("Trigger key " + triggerKey + " is already in used by " + quartzEndpoint); + throw new IllegalArgumentException("Trigger key " + triggerKey + " is already in use by " + quartzEndpoint); } } } http://git-wip-us.apache.org/repos/asf/camel/blob/62af8b8a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java index 66a620f..7444b2b 100644 --- a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java +++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzNameCollisionTest.java @@ -55,7 +55,7 @@ public class QuartzNameCollisionTest { Assert.fail("Should have thrown an exception"); } catch (FailedToCreateRouteException e) { String reason = e.getMessage(); - Assert.assertEquals(reason.indexOf("Trigger key myGroup.myTimerName is already in used") >= 0, true); + Assert.assertEquals(reason.indexOf("Trigger key myGroup.myTimerName is already in use") >= 0, true); } }