elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.53k stars 24.9k forks source link

network.bind_host does not support arrays #15340

Closed dadoonet closed 8 years ago

dadoonet commented 8 years ago

When you define in elasticsearch.yml:

network.bind_host: "NONEXSISTINGADDRESS"

It fails as expected:

Exception in thread "main" BindTransportException[Failed to resolve host [null]]; nested: UnknownHostException[NONEXSISTINGADDRESS: unknown error];
Likely root cause: java.net.UnknownHostException: NONEXSISTINGADDRESS: unknown error
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at org.elasticsearch.common.network.NetworkUtils.getAllByName(NetworkUtils.java:203)
    at org.elasticsearch.common.network.NetworkService.resolveInetAddress(NetworkService.java:200)
    at org.elasticsearch.common.network.NetworkService.resolveBindHostAddress(NetworkService.java:111)
    at org.elasticsearch.transport.netty.NettyTransport.bindServerBootstrap(NettyTransport.java:430)
    at org.elasticsearch.transport.netty.NettyTransport.doStart(NettyTransport.java:319)
    at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
    at org.elasticsearch.transport.TransportService.doStart(TransportService.java:170)
    at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
    at org.elasticsearch.node.Node.start(Node.java:254)
    at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:221)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:287)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.

When you wrap it in an array, it's totally ignored:

network.bind_host: ["NONEXSISTINGADDRESS"]
[2015-12-09 18:00:29,443][INFO ][transport                ] [Collector] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}, {[fe80::1]:9300}, {[::1]:9300}

It means that you can't define a list of bind_host as:

network.bind_host: ["_eth0:ipv4_", "_lo:ipv4_"]

From discussion: https://discuss.elastic.co/t/es-2-1-only-bind-on-localhost/36720

rmuir commented 8 years ago

This was never supported, we added it for 2.2: #13954

Although IMO, separately the real problem here is that the wrong data type was passed in for a setting, since that one did not support arrays, and nothing gave an error about that

dadoonet commented 8 years ago

Thanks! I was wondering why it was correct in code and when I was running a unit test... Was on 2.x branch! :(

I'm closing this then. I think your comment is already covered by another issue IIRC.

dadoonet commented 8 years ago

BTW I think we don't have unit test for multiple addresses in 2.x. I just looked at NetworkServiceTests. Do you think I should send a PR to add this test?

public void testBindMultipleAddresses() throws Exception {
    NetworkService service = new NetworkService(Settings.EMPTY);
    InetAddress[] addresses = service.resolveBindHostAddresses(new String[]{"127.0.0.1", "127.0.0.2"});
    assertThat(addresses.length, is(2));
}
rmuir commented 8 years ago

as long as it does not actually bind or rely on local configuration (e.g. number of interfaces) its a good idea.