From 8a34ca0ec742f9d3e71211802ac235a7ae88789b Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Wed, 21 Dec 2016 17:19:05 -0500 Subject: [PATCH] Clean up connection resources on failed connect. --- .../transport/amqp/client/AmqpConnection.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java index c6c994daaf..c252d1fb05 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/AmqpConnection.java @@ -165,13 +165,21 @@ public class AmqpConnection extends AmqpAbstractResource implements } }); - if (connectTimeout <= 0) { - future.sync(); - } else { - future.sync(connectTimeout, TimeUnit.MILLISECONDS); - if (getEndpoint().getRemoteState() != EndpointState.ACTIVE) { - throw new IOException("Failed to connect after configured timeout."); + try { + if (connectTimeout <= 0) { + future.sync(); + } else { + future.sync(connectTimeout, TimeUnit.MILLISECONDS); + if (getEndpoint().getRemoteState() != EndpointState.ACTIVE) { + throw new IOException("Failed to connect after configured timeout."); + } } + } catch (Throwable error) { + try { + close(); + } catch (Throwable ignore) {} + + throw error; } } }