9 Replies Latest reply on Oct 25, 2002 12:49 PM by apdo

    Connection pool issues

      I've run into some issues with connection in JBoss 3. I am trying to deploy some BMP Entity beans that worked just fine in 2.4. I immediately ran into a problem with beta1 that I traced to the fact that I was not explicitly closing database connections in my beans. My code essentially looked like:

      public String foo()
      {
      ...
      CallableStatement cs = datasource.getConnection.prepareCall(sql);
      ...
      return str;
      }

      I relied on the Container to clean up and close the connection. The problem was that this was not happening so I was running out of connections.

      Then obvious fix was to change the above to:

      public String foo()
      {
      ...
      Connection conn = datasource.getConnection();
      CallableStatement cs = conn.prepareCall(sql);
      ...
      conn.close();
      return str;
      }

      This fixed the problem in beta1 but when I tried RC1, I again ran into problems.

      With RC1, then problem is when foo() calls another method, say bar(), before closing the connection. bar() is very similar to foo() in that it also gets a connection (from the same connection pool). The sequence is basically that foo() gets a connection, bar() gets a connection, bar() closes its connection, foo() closes its connection(). Somewhere in this process, a NullPointerException is thrown back to the client. If I change my code so that foo() closes its connection before calling bar(), everything works fine.

      This leads to a couple of questions:
      1. Do I have to close connections in the bean or should I be able to rely on the container?

      2. Do I have to close connections before making calls to other methods that get connections?

      Thanks,
      Dan.

        • 1. Re: Connection pool issues
          davidjencks

          This might be a bug. Is there any chance you could send me the code so I could look at what is going on? If you wanted to write a failing test case to demonstrate the problem that would be even better, but I'd be happy with the code to try.

          Are you calling bar through a remote interface?

          Thanks
          david jencks
          davidjencks@directvinternet.com

          • 2.

             

            • 3. Re: Connection pool issues

              Let me try again. My original attempt to post a message with an attachment got screwed up.

              The attached file has a small test case that illustrates the problem. I've set it up so that it can easily be modified to fail or not by modifying environment entries in ejb-jar.xml file. You also can set up the connection pool in jboss.xml and the relevant queries in ejb-jar.xml.

              I've also marked "foo", "bar" and the call to "bar" in the code.

              In answer to your question, bar is a finder method so I'm calling it through the remote home interface.

              Thanks,
              Dan.

              • 4. Re: Connection pool issues
                davidjencks

                After thinking about this some more I realized what the problem is and why it has just appeared. For now:

                1. You should ALWAYS close connections yourself. The container has no way of knowing...and won't actually close them for you.

                2. With todays code, unless you use the firebird jca-jdbc driver, you need to close connections before calling another ejb. This is due to some problems with the jboss-jdbc.rar wrapper. I should have it fixed soon one way or another.

                Thanks for reporting this problem.

                • 5. Re: Connection pool issues

                  Thanks for the info, David.

                  As far as point 1 is concerned, I guess I was under the mistaken impression that a connection was somehow registered with a transaction and part of the end transaction process was to close associated connections. This certainly seemed to be the case with 2.4.

                  Anyway, I guess I have some code changes ahead of me :-(.

                  Thanks again,
                  Dan.

                  • 6. Re: Connection pool issues
                    davidjencks

                    I've written a new wrapper that fixes the problems noted here. (you still have to close your connection handles, but you can call outside your ejb while holding a connection).

                    Read about it at http://sourceforge.net/tracker/index.php?func=detail&aid=546958&group_id=22866&atid=381174

                    • 7. Re: Connection pool issues
                      yasirsk

                      Im not entirely certain where this error is originating from , but it seems to be a variant of the same problem. I have a JSP that calls a session bean which calls a finder method. The JSP then calls another session bean that acccesses the database. (2 database calls). Connections are looked up right before the call and closed immediatly after the database operation.

                      This works fine when for a little while, however after 4-5 calls (refresh the browser) , the following stack begins to appear

                      13:14:11,828 ERROR [STDERR] java.lang.reflect.UndeclaredThrowableException:
                      13:14:11,828 ERROR [STDERR] java.rmi.ServerException: disconnect(ManagedConnection mc, Object c) cal
                      led with unknown managed connection; nested exception is:
                      java.lang.IllegalArgumentException: disconnect(ManagedConnection mc, Object c) called with u
                      nknown managed connection
                      13:14:11,843 ERROR [STDERR] java.lang.IllegalArgumentException: disconnect(ManagedConnection mc, Obj
                      ect c) called with unknown managed connection
                      13:14:11,843 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2.unreg
                      isterAssociation(BaseConnectionManager2.java:496)
                      13:14:11,843 ERROR [STDERR] at org.jboss.resource.connectionmanager.BaseConnectionManager2.disco
                      nnect(BaseConnectionManager2.java:469)
                      13:14:11,843 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionManager.disc
                      onnect(CachedConnectionManager.java:358)
                      13:14:11,843 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionManager.push
                      MetaAwareObject(CachedConnectionManager.java:130)
                      13:14:11,843 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.
                      invokeHome(CachedConnectionInterceptor.java:173)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invokeHo
                      me(StatefulSessionInstanceInterceptor.java:128)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTx
                      Interceptor.java:98)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInte
                      rceptorCMT.java:167)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCM
                      T.java:52)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.ja
                      va:109)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.StatefulSessionContainer.invokeHome(StatefulSession
                      Container.java:368)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(
                      BaseLocalContainerInvoker.java:251)
                      13:14:11,875 ERROR [STDERR] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$HomeProxy.i
                      nvoke(BaseLocalContainerInvoker.java:375)
                      13:14:11,875 ERROR [STDERR] at $Proxy408.create(Unknown Source)
                      13:14:11,875 ERROR [STDERR] at org.apache.jsp.salsaBrowserClient$jsp._jspService(salsaBrowserClient.jsp)

                      • 8. Re: Connection pool issues

                        Thanks, David. Your fix works just fine.

                        Dan.

                        • 9. Re: Connection pool issues

                          Here is the settup that cause my some problem

                          Note:
                          EJB SessionFacade has method "rejectDocument"
                          EJB ApprovalCycleBean has method "ACReject"

                          rejectDocument and ACReject methods are actually both call reject in my code. however for clarity in my explanation I name them with different name.

                          There is a SessionFacade (SLSB) from which user call the "rejectDocument" method telling to reject a specific Document. For this we get the

                          The SessionFacade call ACReject method of the the ApprovalCycleBean (BMP Entity Bean). To generate a email notifaction content, the ApprovalCycleBean access a DocumentBean (CMP Entity Bean). This cause the following error. Not that the error do not occure in the ApprovalCycleBean but in the SessionFacade when we get out of the ACReject method. It seams that the error occure in the container code between the call to ACReject in SessionFacade and the ACReject method execution of the ApprovalCycleBean.

                          Note that this didn't occure in jboss-3.0.0_tomcat-4.0.3 but occure in jboss-3.0.3_tomcat-4.0.5. I still want to use jboss-3.0.3 since it is a lot faster than 3.0.0

                          For now what i do is that form the ApprovalCycleBean a use DAO (direct SQL) to access the database data.

                          What should i do to prevent this problem?

                          Here is my stack trace


                          Thank you in advance


                          2002-10-25 11:23:17,822 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException, causedBy:
                          java.lang.IllegalArgumentException: disconnect(ManagedConnection mc: null, Object c: org.jboss.resource.adapter.jdbc.local.LocalConnection@9d3f8b) called with unknown managed connection
                          at org.jboss.resource.connectionmanager.BaseConnectionManager2.unregisterAssociation(BaseConnectionManager2.java:661)
                          at org.jboss.resource.connectionmanager.BaseConnectionManager2.disconnect(BaseConnectionManager2.java:619)
                          at org.jboss.resource.connectionmanager.CachedConnectionManager.disconnect(CachedConnectionManager.java:371)
                          at org.jboss.resource.connectionmanager.CachedConnectionManager.popMetaAwareObject(CachedConnectionManager.java:160)
                          at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:190)
                          at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:90)
                          at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:152)
                          at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
                          at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
                          at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
                          at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
                          at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
                          at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
                          at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
                          at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
                          at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:301)
                          at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
                          at $Proxy111.reject(Unknown Source)
                          at com.solabs.alibaba.businesstier.AlibabaSessionFacadeBean.reject(AlibabaSessionFacadeBean.java:261)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                          at java.lang.reflect.Method.invoke(Method.java:324)
                          at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)
                          at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
                          at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)
                          at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
                          at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
                          at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
                          at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
                          at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
                          at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:313)
                          at org.jboss.ejb.Container.invoke(Container.java:712)
                          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                          at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:381)
                          at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                          at java.lang.reflect.Method.invoke(Method.java:324)
                          at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
                          at sun.rmi.transport.Transport$1.run(Transport.java:148)
                          at java.security.AccessController.doPrivileged(Native Method)
                          at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
                          at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
                          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
                          at java.lang.Thread.run(Thread.java:536)