NIFI-492: When attempting to get a connection from the pool, if we create a new one and encounter an error, should ensure we close the new connection

This commit is contained in:
Mark Payne 2015-04-07 14:16:54 -04:00
parent 39735c30bc
commit 8d20b82095
1 changed files with 14 additions and 0 deletions

View File

@ -314,6 +314,11 @@ public class EndpointConnectionPool {
if ( protocol.isDestinationFull() ) {
logger.warn("{} {} indicates that port's destination is full; penalizing peer", this, peer);
penalize(peer, penalizationMillis);
try {
peer.close();
} catch (final IOException ioe) {
}
continue;
} else if ( protocol.isPortInvalid() ) {
penalize(peer, penalizationMillis);
@ -359,6 +364,15 @@ public class EndpointConnectionPool {
}
}
} while ( connection == null || codec == null || commsSession == null || protocol == null );
} catch (final Throwable t) {
if ( commsSession != null ) {
try {
commsSession.close();
} catch (final IOException ioe) {
}
}
throw t;
} finally {
if ( !addBack.isEmpty() ) {
connectionQueue.addAll(addBack);