Clean up connection resources on failed connect.

This commit is contained in:
Timothy Bish 2016-12-21 17:19:05 -05:00
parent ef97b67f00
commit 8a34ca0ec7
1 changed files with 14 additions and 6 deletions

View File

@ -165,13 +165,21 @@ public class AmqpConnection extends AmqpAbstractResource<Connection> 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;
}
}
}