3 Replies Latest reply on Oct 24, 2016 6:11 PM by spatwary04

    Wildfly10  Remote EJB calls to another EJB on another Wildlfy 10 instance leaking jdbc connections

    spatwary04 Newbie

      we are migrating from jboss 4.2 to wildlfy 10 . We have a  app(client)  which collects data from another more than one app(servers)  using remote  calls from slsbs  deployed on client to slsbs (stateless session beans ) deployed on these servers.

      Below is the code:

      Below is sample method how are using it:

       

      private void synctest(TestServer server ) throws Exception

          {

                     Context ejbRootNamingContext=null;

              Context context=null;

              try

              {

                  context= serviceLocator.getServerContext(server.getHostAddress(), 1199);

                  ejbRootNamingContext=(Context) context.lookup("java:");

                  ServerService is = serviceLocator.getService(ejbRootNamingContext, server.getHostAddress(),

                                                               IQVMSServerConstants.DEFAULT_JNDI_PORT,

                                                               "/ear-filename/ejb-jar-name/ServiceBean!com.test.ServiceRemote",

                                                               ServerService.class );

                 

                  List<TestGroups> groups = is.listAllTestGroups();

                  // persist the groups in local database.

                  List<TestGroups2> groups2 = is.listTestGroups2();

                  // persist the group2s in local database.

              catch( Exception exc )

              {

                  logger.log( Level.SEVERE, "Cannot sync groupsfrom server: " + server, exc );

              }

              finally {

                  try {

                      // close the EJB naming JNDI context

                      ejbRootNamingContext.close();

                      logger.log(Level.FINEST,"closed ejbRootNamingContext");

                  } catch (Throwable t) {

                      logger.log( Level.SEVERE, "unable to close ejbRootNamingContext"+t.getMessage() );

                  }

                  /*try {

                      // also close our other JNDI context since we are done with it too

                     // context.close(); --- Commented out this code if uncommented getting excpetions . Does not seems to work . Dont know the reason.

                  } catch (Throwable t) {

                      // log and ignore

                  }*/

              }

          }

       

       

      Another use case is in the loop of servers:

      private void collectusing loop(List<TestServer> server ) throws Exception

          {

                     Context ejbRootNamingContext=null;

              Context context=null;

          for(TestServer aggrServer : servers)

                  {

              try

              {

                  context= serviceLocator.getServerContext(server.getHostAddress(), 1199);

                  ejbRootNamingContext=(Context) context.lookup("java:");

                  ServerService is = serviceLocator.getService(ejbRootNamingContext, server.getHostAddress(),

                                                               IQVMSServerConstants.DEFAULT_JNDI_PORT,

                                                               "/ear-filename/ejb-jar-name/ServiceBean!com.test.ServiceRemote",

                                                               ServerService.class );

                 

                  List<TestData> testdata= is.listTestData();

                  // persist the testdatain local database.

            

             

              catch( Exception exc )

              {

                  logger.log( Level.SEVERE, "Cannot sync datafrom server: " + server, exc );

              }

              finally {

                  try {

                      // close the EJB naming JNDI context

                      ejbRootNamingContext.close();

                      logger.log(Level.FINEST,"closed ejbRootNamingContext");

                  } catch (Throwable t) {

                      logger.log( Level.SEVERE, "unable to close ejbRootNamingContext"+t.getMessage() );

                  }

                  /*try {

                      // also close our other JNDI context since we are done with it too

                     // context.close(); --- Commented out this code if uncommented getting excpetions . Does not seems to work . Dont know the reason.

                  } catch (Throwable t) {

                      // log and ignore

                  }*/

              }

      }

          }

       

       

      serviceLocator:

       

        public Context getServerContext( String host, int port )

              throws Exception

          {

                 //In wildfly   After reading the doumentation we changed it  to use http remoting

                      Properties clientProp = new Properties();

                      clientProp.put( "java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory" );

                      clientProp.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                      clientProp.put( "java.naming.provider.url", "http-remoting://"+host+":"+port );

                      clientProp.put(Context.SECURITY_PRINCIPAL, "iq");

                      clientProp.put(Context.SECURITY_CREDENTIALS, "sunshine");

                      clientProp.put("jboss.naming.client.ejb.context", true);

                      clientProp.put("org.jboss.ejb.client.scoped.context","true");

                     // logger.log(Level.SEVERE, "before setting  InitialContext");

              return new InitialContext(clientProp);

          }

       

      public <T> T getService( Context ctx, String serviceName, Class<T> c )

              throws Exception

          {

              //String serviceNameasejb=serviceName.replaceFirst("/", "");

              return c.cast( ctx.lookup( serviceName ) );

          }

         

          public <T> T getService( Context ejbcontext,String host, int port, String serviceName, Class<T> c )

              throws Exception

          {

             

               try{

             

              return getService( ejbcontext, serviceName, c );

               }

               finally{

                 

                  

                 

               }

          }

       

      In jboss 4.2 we were creating intialcontext by passing host and port  for each servers.

       

        Hashtable<String,String> props = new Hashtable<String,String>();

              props.put( "java.naming.provider.url", host + ":" + port );

             

              return new InitialContext( props );

       

       

       

       

      After ruuning a while we get    javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms]).

        • 1. Re: Wildfly10  Remote EJB calls to another EJB on another Wildlfy 10 instance leaking jdbc connections
          Tomaz Cerar Master

          Where do you use database? from this code or stracktraces noting of such is shown.

           

          Also on client you should be closing initial context when no longer using it.

           

          First take a look at serve side ejb code and look how it is working with database,

          maybe you are just missing some .close() in you code somewhere.

           

          also you could enable spying on unclosed connections for your datasource, so you can see who is  holding the open connections.

          • 2. Re: Wildfly10  Remote EJB calls to another EJB on another Wildlfy 10 instance leaking jdbc connections
            spatwary04 Newbie

            Tomar,

            The code you are seeing is remote ejb client code. we also tried closing initial context but doing that it was closing db connection very fast and were getting exception where context is closed when other threads were trying to access it.  so we changed our code to

            ejbRootNamingContext=(Context) serviceLocator.getServerContext(server.getHostAddress(), IQVMSServerConstants.DEFAULT_JNDI_PORT).lookup("java:");

             

            and closing the context as before.

             

             

            For the Below call from client :

            List<TestGroups> groups = is.listAllTestGroups();

            A  call to remote stateless session bean  will be made .

            Below is the server side code which is a simple stateless bean which uses jpa( hibernate )  to get data.

             

            @Stateless

            public class ServiceBean implements ServiceLocal, ServiceRemote

            {

               private @PersistenceContext(unitName="VMSDB") EntityManager entityManager;

                private IQGroupDAO groupDAO;

                @PostConstruct

                public void initialize()

                {

                    groupDAO = new IQGroupDAO( entityManager );

                }

             

                @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

                public List<IQResourceGroup> listAllTestGroups() throws Exception

                {

                    List<IQResourceGroup> retGroups = new ArrayList<IQResourceGroup>();

                    List<IQResourceGroup> groups = groupDAO.listAllResourceGroups();

                    return retGroups;

             

             

                }

            }

            • 3. Re: Wildfly10  Remote EJB calls to another EJB on another Wildlfy 10 instance leaking jdbc connections
              spatwary04 Newbie

              I see exception on server side when ever there a connection leak.

               

              2016-10-24 17:16:32,835 ERROR [org.jboss.as.ejb3.remote] (EJB default - 5) WFLYEJB0150: Could not write method invocation failure for method public abstract java.util.List package.class.listAllTestGroups() throws java.lang.Exception on bean named AsmToCvocGroupProbeAggregateServiceBean for appname aerver modulename ejbjarname distinctname  due to: java.io.IOException: WFLYEJB0422: Could not open message outputstream for writing to Channel

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.writeMethodInvocationResponse(MethodInvocationMessageHandler.java:355)

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$600(MethodInvocationMessageHandler.java:68)

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:238)

                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_25]

                  at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_25]

                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]

                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]

                  at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]

                  at org.jboss.threads.JBossThread.run(JBossThread.java:320)

              Caused by: org.jboss.remoting3.NotOpenException: Writes closed

                  at org.jboss.remoting3.remote.RemoteConnectionChannel.openOutboundMessage(RemoteConnectionChannel.java:115)

                  at org.jboss.remoting3.remote.RemoteConnectionChannel.writeMessage(RemoteConnectionChannel.java:307)

                  at org.jboss.as.ejb3.remote.protocol.versionone.ChannelAssociation.acquireChannelMessageOutputStream(ChannelAssociation.java:68)

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.writeMethodInvocationResponse(MethodInvocationMessageHandler.java:353)

                  ... 8 more