You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2010/11/20 08:17:25 UTC

[jira] Commented: (CAMEL-3349) Race condition found in CxfRsEndpoint while getting the endpoint binding under load and performing sync and async invocation

    [ https://issues.apache.org/activemq/browse/CAMEL-3349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=63425#action_63425 ] 

Claus Ibsen commented on CAMEL-3349:
------------------------------------

Nice catch.

I wonder if the initialization of the binding can be done in doStart. This is much better as it would avoid the synchronized block on the getter. Which I assume is invoked lazy at runtime on processing a new Exchange.

Generally initialization should be done in doStart because starting it is single threaded and we don't care _so much_ about performance at startup.

> Race condition found in CxfRsEndpoint while getting the endpoint binding under load and performing sync and async invocation
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-3349
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-3349
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-cxf
>    Affects Versions: 2.2.0, 2.3.0, 2.4.0, 2.5.0
>            Reporter: Ashwin Karpe
>            Assignee: Ashwin Karpe
>            Priority: Critical
>             Fix For: 2.6.0
>
>         Attachments: camel-cxf-race-condition.patch
>
>
> The CxfRsEndpoint's getBinding method is not thread safe. At a customer site, I ran into an issue at startup if 2 threads raced to perform sync and async invocation, the code for getBinding (given below) would react in the following way.
>       - Thread 1 would proceed to create a binding object 
>       - Thread 2 would mean while still find the  binding to be null and proceed to create a new binding
>       - Meanwhile thread one would have its binding and set the Atomic boolean for binding initialized and proceed to set the HeaderStrategy.
>       - Thread 2 meanwhile would overwrite the original binding object and find that Atomic boolean already set and would have no way to associate a HeaderFilterStrategy object since the flag is up.
>       - In the absence of a HeaderFilterStrategy, copying of ProtocolHeaders etc will throw exceptions on every following request/invocation.
> --------------------------------------------------
>     public CxfRsBinding getBinding() {
>         if (binding == null) {
>             binding = new DefaultCxfRsBinding();
>             if (LOG.isDebugEnabled()) {
>                 LOG.debug("Create default CXF Binding " + binding);
>             }
>         } 
>         
>         if (!bindingInitialized.getAndSet(true) && binding instanceof HeaderFilterStrategyAware) {
>             ((HeaderFilterStrategyAware)binding).setHeaderFilterStrategy(getHeaderFilterStrategy());
>         }
>         
>         return binding;
>     }
> ------------------------------------------------

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.