Remote Naming EJB Invocation is not releasing EJBClientContext after close and leaking memory in JBoss EAP 6.4 CP21

Solution Unverified - Updated -

Issue

We are seeing a memory leak even though we are closing the remote naming context as such:

Remote Naming used to invoke EJB is not releasing EJBClientContext. remoteNamingContext.close() is resulting in EJBClientContext.close() which closes the connections, but it looks like the EJBClientContext objects are unable to finalize as it appears TCCLEJBClientContextSelectorService is still referencing them.

  private Context getRemoteNamingInitialContext(String host, Integer port, String user, String pass, boolean useEjbContext) throws NamingException {
    Properties env = new Properties();
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    if(useEjbContext) 
      env.put("jboss.naming.client.ejb.context", "true");
    env.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
    env.put("java.naming.provider.url", String.format("remote://%s:%d", host, port));
    env.put(Context.SECURITY_PRINCIPAL, user);
    env.put(Context.SECURITY_CREDENTIALS, pass);
    return new InitialContext(env);
  }

    Context ctx = null;
    try {
      ctx = getRemoteNamingInitialContext(host, port, user, pass, true);
      Hello ejb = (Hello) ctx.lookup("singleton-timer/HelloBean!com.jboss.examples.ejb.Hello");
      ejb.hello();
    } catch(Throwable t) {
      t.printStackTrace();
    } finally {
      try {
        if(ctx != null) {
          ctx.close();
          ctx = null;
        }
      } catch(Throwable t) {
        t.printStackTrace();
      }
    }
The EJBClientContexts are all retained in org.jboss.as.ejb3.remote.TCCLEJBClientContextSelectorService's identifiableContexts map:

Class Name                                                                                                              | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
org.jboss.threads.JBossThread @ 0x76f2e50d0  EJB default - 9 Thread                                                     |        6,405 |          128 |           512,400 |         9,152
'- contextClassLoader org.jboss.modules.ModuleClassLoader @ 0x76e819c60                                                 |        6,405 |           88 |           512,400 |       137,496
   '- classes java.util.Vector @ 0x76ec1d098                                                                            |        6,405 |           32 |           512,400 |       112,352
      '- elementData java.lang.Object[640] @ 0x76f3cb800                                                                |        6,405 |        2,576 |           512,400 |       112,320
         '- [160] class org.jboss.as.ejb3.remote.DefaultEJBClientContextSelector @ 0x76eed97d8                          |        6,405 |           16 |           512,400 |           312
            '- INSTANCE org.jboss.as.ejb3.remote.DefaultEJBClientContextSelector @ 0x76eed9848                          |        6,405 |           24 |           512,400 |            24
               |- tcclEJBClientContextService org.jboss.as.ejb3.remote.TCCLEJBClientContextSelectorService @ 0x76ef8ba50|        6,404 |           24 |           512,320 |     2,308,232
               |  '- identifiableContexts java.util.concurrent.ConcurrentHashMap @ 0x76ef8bb18                          |        6,404 |           64 |           512,320 |     2,307,992
               |     '- table java.util.concurrent.ConcurrentHashMap$Node[16384] @ 0x7bd508000                          |        6,404 |       65,552 |           512,320 |     2,307,928
               |        |- [3054] java.util.concurrent.ConcurrentHashMap$Node @ 0x770900950                             |            5 |           32 |               400 |         1,752
               |        |  |  |- val org.jboss.ejb.client.EJBClientContext @ 0x76fec29f8                                |            1 |           80 |                80 |         2,816
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 6.4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content