Skip to content

Commit

Permalink
JBJCA-1398 Connection leak when there is an exception during getConne…
Browse files Browse the repository at this point in the history
…ction for NoTransaction resource adapter
  • Loading branch information
maeste committed Dec 12, 2019
1 parent 23ee7c2 commit c601f98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
Expand Up @@ -1089,18 +1089,40 @@ protected void managedConnectionReconnected(ConnectionListener cl) throws Resour
}

/**
* For polymorphism.
* <p>
*
* Do not invoke directly, use disconnectManagedConnection
* which does the relevent exception handling
*
* @param cl connection listener
* @throws ResourceException for exception
*/
protected void managedConnectionDisconnected(ConnectionListener cl) throws ResourceException
{
//Nothing as default
}
Throwable throwable = null;
try
{
cl.delist();
}
catch (Throwable t)
{
throwable = t;
}

//if there are no more handles and tx is complete, we can return to pool.
if (cl.isManagedConnectionFree())
{
log.tracef("Disconnected isManagedConnectionFree=true cl=%s", cl);

returnManagedConnection(cl, false);
}
else
{
log.tracef("Disconnected isManagedConnectionFree=false cl=%s", cl);
}

// Rethrow the error
if (throwable != null)
{
throw new ResourceException(bundle.couldNotDelistResourceThenTransactionRollback(), throwable);
}
}

/**
* Register connection with connection listener.
Expand Down
Expand Up @@ -572,39 +572,6 @@ protected void managedConnectionReconnected(ConnectionListener cl) throws Resour
}
}

/**
* {@inheritDoc}
*/
protected void managedConnectionDisconnected(ConnectionListener cl) throws ResourceException
{
Throwable throwable = null;
try
{
cl.delist();
}
catch (Throwable t)
{
throwable = t;
}

//if there are no more handles and tx is complete, we can return to pool.
if (cl.isManagedConnectionFree())
{
log.tracef("Disconnected isManagedConnectionFree=true cl=%s", cl);

returnManagedConnection(cl, false);
}
else
{
log.tracef("Disconnected isManagedConnectionFree=false cl=%s", cl);
}

// Rethrow the error
if (throwable != null)
{
throw new ResourceException(bundle.couldNotDelistResourceThenTransactionRollback(), throwable);
}
}

/**
* {@inheritDoc}
Expand Down

0 comments on commit c601f98

Please sign in to comment.