[TRANSPORT] Close all resources if doStart fails

Closes #9898
This commit is contained in:
Simon Willnauer 2015-02-26 11:01:36 +01:00 committed by Alexander Reelsen
parent db2caa54cd
commit ed7f6526b9
1 changed files with 54 additions and 49 deletions

View File

@ -221,12 +221,10 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
@Override @Override
protected void doStart() throws ElasticsearchException { protected void doStart() throws ElasticsearchException {
boolean success = false;
try {
clientBootstrap = createClientBootstrap(); clientBootstrap = createClientBootstrap();
if (settings.getAsBoolean("network.server", true)) {
if (!settings.getAsBoolean("network.server", true)) {
return;
}
final OpenChannelsHandler openChannels = new OpenChannelsHandler(logger); final OpenChannelsHandler openChannels = new OpenChannelsHandler(logger);
this.serverOpenChannels = openChannels; this.serverOpenChannels = openChannels;
@ -248,7 +246,7 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
if (DEFAULT_PROFILE.equals(name)) { if (DEFAULT_PROFILE.equals(name)) {
profileSettings = settingsBuilder() profileSettings = settingsBuilder()
.put(profileSettings) .put(profileSettings)
.put("port", profileSettings.get("port", settings.get("port", this.settings.get("transport.tcp.port", DEFAULT_PORT_RANGE)))) .put("port", profileSettings.get("port", this.settings.get("transport.tcp.port", DEFAULT_PORT_RANGE)))
.build(); .build();
} else { } else {
// if profile does not have a port, skip it // if profile does not have a port, skip it
@ -275,6 +273,13 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
InetSocketAddress publishAddress = createPublishAddress(publishHost, publishPort); InetSocketAddress publishAddress = createPublishAddress(publishHost, publishPort);
this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(boundAddress), new InetSocketTransportAddress(publishAddress)); this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(boundAddress), new InetSocketTransportAddress(publishAddress));
} }
success = true;
} finally {
if (success == false) {
doStop();
}
}
}
@Override @Override
public Map<String, BoundTransportAddress> profileBoundAddresses() { public Map<String, BoundTransportAddress> profileBoundAddresses() {