4 Replies Latest reply on Feb 2, 2007 1:02 AM by Shai Bentin

    db connection leak some advice please

    Shai Bentin Newbie

      I have recently deployed a large jbpm application. This is actually an extension to a J2ee application which has been running for two years. Since this deployment my system exhausted the connection pool every few hours. It looks like JBPM is responsible (or rather me misusing it....)

      Anyhow, I read somewhere that not closing JbpmContext could be the reason for this problem. However, I'm running most of my jbpm calls from code that does other things and which uses a UserTransaction (I'm working with ejb 2.0 on jboss4.0.3Sp1). If I try to close the context it complains I can't commit when autocommit is set!, so basically I commit my userTransaction and don't close the JbpmContext.

      Here are my configuration files:

      <hibernate-configuration>
       <session-factory>
      
      
       <!-- Datasource configuration -->
       <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
       <property name="hibernate.connection.datasource">java:/OracleDS</property>
       <property name="hibernate.show_sql">false</property>
       <property name="hibernate.format_sql">false</property>
      <!--
       <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
      -->
       <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
       <property name="hibernate.connection.release_mode">after_statement</property>
      <!--
       <property name="hibernate.transaction.auto_close_session">true</property>
      -->
       <property name="hibernate.transaction.flush_before_completion">true</property>
      
       <!-- other hibernate properties
       <property name="hibernate.show_sql">true</property>
       <property name="hibernate.format_sql">true</property>
       -->
      


      and jbpmConfig:
      <jbpm-configuration>
      
       <jbpm-context>
       <service name='persistence' factory='org.jbpm.persistence.db.DbPersistenceServiceFactory'>
       <field name="isTransactionEnabled"><false /></field>
       </service>
       <service name='message' factory='org.jbpm.msg.db.DbMessageServiceFactory' />
       <!-- service name='scheduler' factory='org.jbpm.scheduler.db.DbSchedulerServiceFactory' /-->
       <service name='logging' factory='org.jbpm.logging.db.DbLoggingServiceFactory' />
       <!-- service name='authentication' factory='org.jbpm.security.authentication.DefaultAuthenticationServiceFactory' /-->
       </jbpm-context>
      
       <!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
       <string name='resource.hibernate.cfg.xml' value='hibernate.cfg.xml' />
       <!-- <string name='resource.hibernate.properties' value='hibernate.properties' /> -->
       <string name='resource.business.calendar' value='org/jbpm/calendar/jbpm.business.calendar.properties' />
       <string name='resource.default.modules' value='org/jbpm/graph/def/jbpm.default.modules.properties' />
       <string name='resource.converter' value='org/jbpm/db/hibernate/jbpm.converter.properties' />
       <string name='resource.action.types' value='org/jbpm/graph/action/action.types.xml' />
       <string name='resource.node.types' value='org/jbpm/graph/node/node.types.xml' />
       <string name='resource.parsers' value='org/jbpm/jpdl/par/jbpm.parsers.xml' />
       <string name='resource.varmapping' value='org/jbpm/context/exe/jbpm.varmapping.xml' />
      
       <bean name='jbpm.task.instance.factory' class='com.emi.framework.infrastructure.workflow.TaskInstanceFactory' singleton='true' />
       <bean name='jbpm.variable.resolver' class='org.jbpm.jpdl.el.impl.JbpmVariableResolver' singleton='true' />
       <long name='jbpm.msg.wait.timout' value='5000' singleton='true' />
      
      </jbpm-configuration>
      


      can someone shed a light?

        • 1. Re: db connection leak some advice please
          Ronald van Kuijk Master

          did you try searching the forum? this has been discussed before afaik. Don't know if it was a bug/configuration issue/... but please check and get back if it you do not find a solution

          • 2. Re: db connection leak some advice please
            Shai Bentin Newbie

            OK. Done alot of investigation but still have a problem. Here is what I got:

            first, I saw that my jbmp.configuration has no effect. i.e to have no transaction support by hibernate i had

            <service name='persistence' factory='org.jbpm.persistence.db.DbPersistenceServiceFactory'>
             <field name="isTransactionEnabled"><false /></field>
             </service>
            

            this did not actually load the attribute what i should have had is this:

            <service name='persistence'>
             <factory>
             <bean class='com.emi.framework.infrastructure.workflow.EmiDbPersistanceServiceFactory'>
             <field name="isTransactionEnabled"><false /></field>
             </bean>
             </factory>
             </service>
            


            Now the transaction is managed by Jboss App Server and not hibernate. Still there is a problem.

            Here is what I do:
            1. user clicks on a link on a web page.
            2. A UserTransaction is opened
            3. JbpmContext is created (JbpmConfiguration.getInstance().createJbpmContext()
            4. TaskMgmntSesion is received and a taskInstance is loaded.
            5. ContextInstance is received from the task
            6. processinstance is received from context
            7. the process is signaled.
            8. Action are run and the process foloows to the next state.
            9 return from signal to method
            10. commit transaction
            11. JbpmContext is closed

            After lots of investigation I know the following:
            1. the connection is opened by Jbpm in the LoadTaskInstance
            2. this connection is not on the hiberanteSession, jdbcContext, ConnectionManager
            3. I could not find it anywhere, so I can not close it.
            4. This connection is not closed and stays open even though transaction is committed or rolledback.
            5. Since this connection is nowhere to be found I can't close it.

            This causes the connection pool to run out very quickly.

            Need help ASAP

            THNX

            • 3. Re: db connection leak some advice please
              Alejandro Guizar Master

              why is the following setting commented?

              <!--
               <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
              -->


              You should not have to change the default connection release mode because your chosen TransactionFactory class already specifies the most appropriate mode.

              Flushing before completion and auto-closing the session are not recommended because jBPM flushes and closes the session for you.

              Hope this helps.

              • 4. Re: db connection leak some advice please
                Shai Bentin Newbie

                I tried as you suggested and commented the flush and release mode and uncommented the transaction factory. Nothing is changed.

                I want to emphasize that everything gets committed or rolledback as it should. My only problem is that the connection is never closed, thus it is never returned to the ManagedConnectionPool.