Uploaded image for project: 'DSpace'
  1. DSpace
  2. DS-2563

Error releasing database connection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Volunteer Needed (View Workflow)
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.8.2, 3.0, 5.1
    • Fix Version/s: None
    • Component/s: DSpace API
    • Labels:
    • Attachments:
      3
    • Comments:
      3
    • Documentation Status:
      Needed

      Description

      I have seen that DSpace initializes new Context objects during its flow.
      This increases the number of application database connections. But the most important problem is the treatment of the objects Context because they are used to demarcate transactions programmatically. When the decision is to handle transactions in this way, the correct way to handle the Context object is:

      Context c = null;
      try

      { c = new Context(); // open a new database connection // process c.commit(); // it does a commit }

      catch (Exception e)

      { if (c != null) c.abort(); // it does a rollback } finally { if (c != null) c.free(); // release the database connection }

      DSpace treats Context objects in a different way:

      Context c = null;
      try { c = new Context(); // open a new database connection // process (*) c.commit(); // it does a commit c.free(); // release the database connection } catch (Exception e) { if (c != null) c.abort(); // it does a rollback }

      As noted above, confirmation of changes (commit) is coupled with the release of the connection (free). If an error happens during processing or commit, the connection will not return to the pool. The accumulation of this error will cause the connection pool to be exhausted and the application will throw the following blocking error:

      Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
      at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:114)
      at org.dspace.storage.rdbms.DatabaseManager.getConnection(DatabaseManager.java:588)
      at org.dspace.core.Context.<init>(Context.java:95)
      at org.dspace.app.xmlui.utils.ContextUtil.obtainContext(ContextUtil.java:89)
      at org.dspace.app.xmlui.utils.ContextUtil.obtainContext(ContextUtil.java:54)
      at org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer.setup(AbstractDSpaceTransformer.java:78)
      ... 113 more
      Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
      at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:958)
      at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
      ... 118 more

      Solution:

      The solution to attack the source of the problem is to change the management of all Context objects to properly close the connection as I mentioned above. This alternative is very intrusive in the base code and I have to change many parts of it.
      Alternatively, the following solution was made: the requirements are managed through a similar pattern to Open Session in View of Hibernate.
      I attach a patch with the solution mentioned above.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              cmcoronel_santafe Mauricio Coronel
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated: