Uploaded image for project: 'Agroal'
  1. Agroal
  2. AG-140

Connection leak caused by failed transaction integration

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 1.9
    • 1.8
    • narayana, pool
    • None
    • Hide

      1. Check out the PoC and run mvn quarkus:dev
      2. Invoke the /hello endpoint several times, checking /metrics for vendor_agroal_active_count
      3. after 5 invocations (max size setting), the pool will be exhausted, and "java.sql.SQLException: Sorry, acquisition timeout!" will be thrown

      Show
      1. Check out the PoC and run mvn quarkus:dev 2. Invoke the /hello endpoint several times, checking /metrics for vendor_agroal_active_count 3. after 5 invocations (max size setting), the pool will be exhausted, and "java.sql.SQLException: Sorry, acquisition timeout!" will be thrown

    Description

      If the following conditions are met:

      • transaction integration is installed;
      • connection checkout has been successful;
      • transactionIntegration.associate(...) (ConnectionPool.java:222) throws an exception,

      then the code that called getConnection() will have no reference to the connection object, hence no ability to close it and return to the pool. The connection won't be reaped or GCed, thus staying in the checked-out state forever, which in turn can lead to connection pool exhaustion.

      The following snippet demonstrates the issue (assuming that Hibernate uses Agroal+Narayana and the transaction is active):

              Foo foo = new Foo();
      
              try {
                  em.merge(foo); // org.hibernate.id.IdentifierGenerationException due to missing ID, transaction aborted
              } catch (Exception e) {
                  // suppress exception
                  LOG.log(Level.WARNING, "merge", e);
              }
              
              // continue using the same EntityManager
              em.find(Foo.class, 0L); // java.sql.SQLException: Exception in association of connection to existing transaction, connection leaked
      

      Obviously, the usage pattern is invalid (must handle the exception properly and must not use EntityManager afterwards), but it shouldn't lead to connection leaks either.

      The compete PoC: https://github.com/dteleguin/agroal-connection-leak-poc

      Attachments

        Activity

          People

            lbarreiro-1 Luis Barreiro
            dmitry.telegin Dmitry Telegin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: