Issue Details (XML | Word | Printable)

Key: MULE-3238
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Andrew Perepelytsya
Reporter: Keith Naas
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Mule

JdbcConnector & JdbcMessageDispatcher are leaving connections open

Created: 17/Apr/08 10:24 AM   Updated: 11/Jun/08 01:32 PM
Component/s: Transport: JDBC
Affects Version/s: 2.0.0
Fix Version/s: 1.4.4, 2.0.1

Time Tracking:
Original Estimate: 4 hours
Original Estimate - 4 hours
Remaining Estimate: 4 hours
Remaining Estimate - 4 hours
Time Spent: Not Specified
Remaining Estimate - 4 hours

Environment: Windows XP, JBoss 4.2.GA

Labels:
User impact: High


 Description  « Hide
From http://www.nabble.com/JdbcConnector-is-leaving-connections-open-to16628200.html:

JdbcMessageDispatcher.executeRequest does not close the connection if there are no results and polling frequency is not set. Another possible issue is that if using a connection pool, the connection is reserved for the entire duration of the loop. If it is long enough, no one other threads in the application can use it. If you have a lot of JdbcConnector endpoints, this can happen pretty easily.

try
        {
            con = connector.getConnection();
            do
            {
                ....
                result = connector.getQueryRunner().query(con, readStmt, params, connector.getResultSetHandler());
                if (result != null)
                {
                    if (staticLogger.isDebugEnabled())
                    {
                        staticLogger.debug("Received: " + result);
                    }
                    break;
                }
                final long sleep = Math.min(connector.getPollingFrequency(), timeout
                    - (System.currentTimeMillis() - t0));
                if (sleep > 0)
                {
                    ....
                    Thread.sleep(sleep);
                }
                else
                {
                    staticLogger.debug("Timeout");  // also, its not really a Timeout, it could just mean that there are not results
                    return null; // Connection Leak!  Call JDBCUtils.commitAndClose(con)?
                }
            }
            while (true);

            ....
            JdbcUtils.commitAndClose(con);
            return message;
        }
        catch (final Exception e)
        {
            JdbcUtils.rollbackAndClose(con);
            throw e;
        }

JdbcConnector will also not close the connection if the connection cannot be bound to the transaction.

public Connection getConnection() throws Exception
    {
        Transaction tx = TransactionCoordination.getInstance().getTransaction();
        if (tx != null)
        {
            if (tx.hasResource(dataSource))
            {
                logger.debug("Retrieving connection from current transaction");
                return (Connection)tx.getResource(dataSource);
            }
        }
        logger.debug("Retrieving new connection from data source");
        Connection con = dataSource.getConnection();

        if (tx != null)
        {
            logger.debug("Binding connection to current transaction");
            try
            {
                tx.bindResource(dataSource, con);
            }
            catch (TransactionException e)
            {
 // Connection leak!  Call JDBCUtils.close(con)?
                throw new RuntimeException("Could not bind connection to current transaction", e);
            }
        }
        return con;
    }


 All   Comments   Work Log   Change History   Transitions   FishEye      Sort Order: Ascending order - Click to sort in descending order
Andrew Perepelytsya added a comment - 24/Apr/08 08:36 AM