{"action":"opened","issue":{"url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/issues/1107","repository_url":"https://api.github.com/repos/wildfly-extras/wildfly-camel","labels_url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/issues/1107/labels{/name}","comments_url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/issues/1107/comments","events_url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/issues/1107/events","html_url":"https://github.com/wildfly-extras/wildfly-camel/issues/1107","id":137269162,"number":1107,"title":"Subsystem handling of Camel CDI context creation events is flawed","user":{"login":"jamesnetherton","id":4721408,"avatar_url":"https://avatars.githubusercontent.com/u/4721408?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesnetherton","html_url":"https://github.com/jamesnetherton","followers_url":"https://api.github.com/users/jamesnetherton/followers","following_url":"https://api.github.com/users/jamesnetherton/following{/other_user}","gists_url":"https://api.github.com/users/jamesnetherton/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesnetherton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesnetherton/subscriptions","organizations_url":"https://api.github.com/users/jamesnetherton/orgs","repos_url":"https://api.github.com/users/jamesnetherton/repos","events_url":"https://api.github.com/users/jamesnetherton/events{/privacy}","received_events_url":"https://api.github.com/users/jamesnetherton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/milestones/7","html_url":"https://github.com/wildfly-extras/wildfly-camel/milestones/4.0.0","labels_url":"https://api.github.com/repos/wildfly-extras/wildfly-camel/milestones/7/labels","id":1144693,"number":7,"title":"4.0.0","description":"Camel Subsystem for WildFly-10.0.x","creator":{"login":"tdiesler","id":244946,"avatar_url":"https://avatars.githubusercontent.com/u/244946?v=3","gravatar_id":"","url":"https://api.github.com/users/tdiesler","html_url":"https://github.com/tdiesler","followers_url":"https://api.github.com/users/tdiesler/followers","following_url":"https://api.github.com/users/tdiesler/following{/other_user}","gists_url":"https://api.github.com/users/tdiesler/gists{/gist_id}","starred_url":"https://api.github.com/users/tdiesler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdiesler/subscriptions","organizations_url":"https://api.github.com/users/tdiesler/orgs","repos_url":"https://api.github.com/users/tdiesler/repos","events_url":"https://api.github.com/users/tdiesler/events{/privacy}","received_events_url":"https://api.github.com/users/tdiesler/received_events","type":"User","site_admin":false},"open_issues":33,"closed_issues":31,"state":"open","created_at":"2015-06-02T10:29:35Z","updated_at":"2016-02-29T14:27:22Z","due_on":"2016-03-31T22:00:00Z","closed_at":null},"comments":0,"created_at":"2016-02-29T14:27:22Z","updated_at":"2016-02-29T14:27:22Z","closed_at":null,"body":"There are some issues with how the subsystem deals with CDI camel contexts.\r\n\r\nThe [CamelContextRegistryImpl](https://github.com/wildfly-extras/wildfly-camel/blob/3b03f8871242281c0331c1cc483fb60ee1c90d84/subsystem/core/src/main/java/org/wildfly/extension/camel/service/CamelContextRegistryService.java#L146) does a number of bootstrapping tasks when a camel context is created. Unfortunately, whenever `@Inject` is used to inject a camel context into a bean, a proxy is created which ends up passing through the `contextCreated` method. In effect, we end up needlessly bootstraping a context that will never be started. \r\n\r\nThe unfortunate side effect to this is that these contexts are not 'unmanaged' and never have their associated `ContextCreateHandlers` cleaned up.\r\n\r\nThe other nasty side effect is that CDI proxies invoke the default constructor on their proxied bean. This usually results in [this code](https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java#L300) being executed. Since the context stop() method is never invoked on the CDI proxy, [this static map](https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/spi/Container.java#L51) is filled with camel contexts that cannot be removed throughout the lifecycle of the container.\r\n\r\nThe result of these issues are potential classloader leaks and the inevitable OutOfMemoryError that follows. "}}