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

memory leak in ClientImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.6
    • 3.2.2, 3.1.15
    • Core, JAX-WS Runtime
    • None
    • wildfly-10.1.0

    • Unknown
    • Patch

    Description

      My app is a web-app and my wildfly has ~ 300 thread. If I understand correctly the code, ClientImpl.responseContext is cleaned only on destroy. We use a lot of service ad some of them have a large output (~10Mb). So, I need a lot of memory for storing ClientImpl.responseContext.

      I try the following patch ant it seems to solve the problem, but it has an
      horrible cast.

      {{
      diff --git a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
      index 428f79454b..b15fb4dff2 100644
      — a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
      +++ b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
      @@ -29,7 +29,7 @@ import java.util.Collections;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      -import java.util.WeakHashMap;
      +import java.util.HashMap;
      import java.util.concurrent.ConcurrentHashMap;
      import java.util.concurrent.Executor;
      import java.util.logging.Level;
      @@ -96,10 +96,10 @@ public class ClientImpl

      protected Map<String, Object> currentRequestContext = new ConcurrentHashMap<String, Object>(8, 0.75f, 4);
      protected Map<Thread, EchoContext> requestContext

      • = Collections.synchronizedMap(new WeakHashMap<Thread, EchoContext>());
        + = Collections.synchronizedMap(new HashMap<Thread, EchoContext>());

      protected Map<Thread, Map<String, Object>> responseContext

      • = Collections.synchronizedMap(new WeakHashMap<Thread, Map<String, Object>>());
        + = Collections.synchronizedMap(new HashMap<Thread, Map<String, Object>>());

      protected Executor executor;

      @@ -1052,5 +1052,8 @@ public class ClientImpl
      }
      }

      -
      + public void releaseLocalThread()

      { + requestContext.remove(Thread.currentThread()); + responseContext.remove(Thread.currentThread()); + }

      }
      diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
      index d963693afd..37b5e2ed02 100644
      — a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
      +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
      @@ -131,6 +131,7 @@ public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implem
      client.getRequestContext().put(Method.class.getName(), method);
      boolean isAsync = isAsync(method);

      + try {
      Object result = null;
      try {
      if (isAsync)

      { @@ -184,6 +185,9 @@ public class JaxWsClientProxy extends org.apache.cxf.frontend.ClientProxy implem }

      }
      return adjustObject(result);
      + } finally

      { + if(client instanceof org.apache.cxf.endpoint.ClientImpl) ((org.apache.cxf.endpoint.ClientImpl)client).releaseLocalThread(); + }

      }
      boolean isAsync(Method m) {
      return m.getName().endsWith("Async")

      }}

      Luca

      Attachments

        1. CXF_7591-patch.txt
          3 kB
          Daniel Kulp

        Issue Links

          Activity

            People

              Unassigned Unassigned
              lbonco_74 Luca Boncompagni
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: