Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-3800

ClientImpl reuse ResponseContext cause ConcurrentModificationException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Duplicate
    • None
    • 2.3.1
    • Core
    • None
    • Unknown

    Description

      In org.apache.cxf.endpoint.ClientImpl.invoke() method, it reuses the existing ResponseContext of current thread from its WeakHashMap. It can cause the ConcurrentModificationException if the proxy client use an Executor to execute an asyc request.

      Thread 1. We call the async request method of generated proxy client, it will call JaxWsClientProxy.invokeAsync(), and it will get the previous ResponseContext of current thread and clear it and reuse it in ClientImpl.

      ClientImpl:
      
        if (context == null) {
           context = new HashMap<String, Object>();
           Map<String, Object> resp = getResponseContext();
           resp.clear();
      

      Thread 2, When CXF got the response from the server, it will use a background thread to process the response, and also it will get the ResponseContext and process the response in ClientImpl

      ClientImpl.onMessage(){
       message.getExchange().setInMessage(message);
       Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>)message.getExchange().getOutMessage().get(Message.INVOCATION_CONTEXT));
      
           // *** Get Response context which could be clean by Thread1 ***
            resCtx = CastUtils.cast((Map<?, ?>)resCtx.get(RESPONSE_CONTEXT)); 
      
            try {
              Object obj[] = processResult(message, message.getExchange(),null, resCtx);
      }
      
      

      Since the ResponseContext in Thread 2 could be clean by the Thread 1 during processing the response message, so it could cause ConcurrentModificationException, or it can cause data error.

      Could you please fix it by creating a new ResponseContext for the new request? thanks.

      David

      Attachments

        Issue Links

          Activity

            People

              dkulp Daniel Kulp
              veaven David Liu
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: