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

CXF Using async WebClient with load distribution failover strategy leads to memory leak

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.1
    • Fix Version/s: 3.0.2
    • Component/s: JAX-RS
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I encountered strange behaviour with using async WebClient. For case of example I create JAXRSClientFactoryBean with failover strategy:

          FailoverFeature feature = new FailoverFeature();
          feature.setTargetSelector(new LoadDistributorTargetSelector());
      
          List<String> alternateAddresses = new ArrayList<String>();
          // addresses are alternate addresses provided at start-up
          alternateAddresses.add("http://localhost:1234");
          alternateAddresses.add("http://localhost:5678");
      
          SequentialStrategy strategy = new SequentialStrategy();
          strategy.setAlternateAddresses(alternateAddresses);
          feature.setStrategy(strategy);
      
          JAXRSClientFactoryBean factoryBean = new JAXRSClientFactoryBean();
          factoryBean.setAddress("http://localhost:1234"); // setting initial address
      
          LoadDistributorTargetSelector targetSelector = new LoadDistributorTargetSelector();
          targetSelector.setStrategy(strategy);
          factoryBean.setConduitSelector(targetSelector);
      
          factoryBean.setServiceClass(SomeService.class);
          List<Feature> features = new ArrayList<Feature>();
          features.add(feature);
          factoryBean.setFeatures(features);
      
          WebClient webClient = factoryBean.createWebClient();
      

      Next I am making invocation of my request:

      Future<Response> post = webClient.path("service/path").async().post(Entity.json(request));
      
      

      After running about 200~300 requests I observed huge memory usage of my component. Made heapdump and investigated that org.apache.cxf.clustering.LoadDistributorTargetSelector is keeping much data in ConcurrentHashMap (and this data is never released in case os AsyncInvoker):

      protected ConcurrentHashMap<InvocationKey, InvocationContext> inProgress 
          = new ConcurrentHashMap<InvocationKey, InvocationContext>();
      
       public void prepare(Message message) {
          ...
          inProgress.putIfAbsent(key, invocation);
       }
      

      Everything would be fine if that map was cleared after the request but in case of AsyncInvoker it is not and quickly leads to OutOfMemoryError. In SyncInvoker map is being cleared by FailoverTargetSelector class:

      public void complete(Exchange exchange) {
      ...
      if (!failover) {
              inProgress.remove(key);
              doComplete(exchange);
          }
      

      Any ideas is it indeed a bug ? Or I am missing something.

        Attachments

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              wsl Mike
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: