Skip to content

Closing a connection with "usageCount > 1" is possible. #16

@rankinc

Description

@rankinc

JdbcPooledConnection.close() says:

    // this should never happen, should we throw an exception or log at warn/error?
    if (usageCount > 0) {
        log.warn("close connection with usage count > 0, " + this);
    }

However, should JdbcPooledConnection.getConnectionHandle() throw a SQLException because (e.g.) testConnection() has failed, then usageCount will still have been incremented when XAPool.getConnectionHandle() tries to close the invalid connection.

The patch is trivial:

// Increment the usage count
usageCount++
try {

   // etc

} catch (SQLException e) {
    // This connection must be invalid, so revert the usage counter.
    // Note: Closing a handle with usageCount > 0 "should never happen".
    --usageCount;
    throw e;
}

Cheers,
Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions