Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apm-server only listens on ipv4 when using 'localhost:8200' as host #1405

Closed
prupert opened this issue Sep 24, 2018 · 7 comments
Closed

apm-server only listens on ipv4 when using 'localhost:8200' as host #1405

prupert opened this issue Sep 24, 2018 · 7 comments

Comments

@prupert
Copy link

prupert commented Sep 24, 2018

I am using the apm-server-6.4.1-1.x86_64 package for CentOS 7 and noticed that the apm-server process only binds to the IPv4 address when using localhost, even though 'localhost' resolves to both IPv4 and IPv6, and IPv6 is fully enabled and working.

config:

apm-server:
  host: "localhost:8200"
# host localhost
localhost has address 127.0.0.1
localhost has IPv6 address ::1

# netstat -tulpn | grep apm
tcp        0      0 127.0.0.1:8200          0.0.0.0:*               LISTEN      12345/apm-server

For other Elastic services, i.e. Elasticsearch, the process does bind to IPv6 as well:

# grep network.host /etc/elasticsearch/elasticsearch.yml
network.host: _local_
# netstat -tulpn | grep 9200
tcp6       0      0 127.0.0.1:9200          :::*                    LISTEN      23456/java
tcp6       0      0 ::1:9200                :::*                    LISTEN      23456/java
@graphaelli
Copy link
Member

apm-server currently listens on only one of the resolved addresses when the listener is specified by host name, preferring ipv4, per the underlying library implementation.

We can turn this into a feature request supporting multiple listeners, perhaps apm-server.hosts as an array, but this does not qualify as a bug.

Some options for working around this:

  • listen only with ipv6 - apm-server.host="[::1]:8200"
  • listen on all interfaces - apm-server.host=:8200 - be sure to filter traffic per interface per your requirements

@graphaelli graphaelli removed the bug label Sep 24, 2018
@prupert
Copy link
Author

prupert commented Sep 25, 2018

Thanks for the clarification. In that case might I suggest to use 127.0.0.1 by default in stead of localhost, because the latter is very confusing. See also the documentation of the underlying library implementation you mentioned:

"The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses."

Users of APM Server should be made aware that they should not use the hostname localhost to connect to the APM Server when IPv6 is enabled.

@OrangeDog
Copy link

I've tried both 0.0.0.0:8200 and :8200, but the server only listens on IPv6 and not IPv4.
I'd say that's definitely a bug.

Only by explicitly putting an assigned IPv4 address will it listen correctly.

@graphaelli
Copy link
Member

@OrangeDog Are you verifying through netstat or sending ipv4 traffic? I don't expect an issue with the latter, since https://codereview.appspot.com/2204048 originally addressed the issue.

If you are unable to complete an v4 request to a dual stack listening on :8200, please provide your OS and apm-server version + installation method (package or source) so that we may attempt to reproduce the issue.

@OrangeDog
Copy link

Checking with netstat. Sorry, you're right it's dual stack and does work fine.

@graphaelli graphaelli removed their assignment Jun 21, 2019
@ghostyusheng
Copy link

when I check APM README.md , I found the reason is ES version is 7.0.1 but apm-server is 7.4, so I changed right version(7.0.1 apm),bind 0.0.0.0:80 ,it worked.

@stuartnelson3
Copy link
Contributor

Closing this as users can bind to all interfaces to listen on ipv4 and ipv6

trentm added a commit to elastic/apm-agent-nodejs that referenced this issue Nov 28, 2022
…7.0.0.1' rather than 'localhost'

Starting in node v17 the defaults for DNS resolution order was
changed (nodejs/node#39987) such that
`dns.lookup()` no longer sorted IPv4 addresses first. This impacts
usage of the *default* APM Server URL (the `serverUrl` config var),
'http://localhost:8200', when using node >=17 because the APM server
only binds to the IPv4 address by default
(elastic/apm-server#1405).

Fixes: #3045
trentm added a commit to elastic/apm that referenced this issue Nov 28, 2022
…6 ambiguity

The current default APM server URL -- 'http://localhost:8200' -- is
ambiguous. "localhost" can resolve to a '127.0.0.1' (IPv4) or '[::1]'
(IPv6).

At least in Node v17 the default `dns.lookup()` ordering of results was
changed to no longer explicitly sort IPv4 addresses first.  That means
that on systems where the default resolver returns '[::1]' first for
"localhost" will result in a broken attempt to talk to a
default-configured local APM server:
  elastic/apm-agent-nodejs#3045
This is because APM server only binds to the IPv4 port:
  elastic/apm-server#1405
trentm added a commit to elastic/apm-agent-nodejs that referenced this issue Dec 8, 2022
…7.0.0.1' rather than 'localhost' (#3049)

Starting in node v17 the defaults for DNS resolution order was
changed (nodejs/node#39987) such that
`dns.lookup()` no longer sorted IPv4 addresses first. This impacts
usage of the *default* APM Server URL (the `serverUrl` config var),
'http://localhost:8200', when using node >=17 because the APM server
only binds to the IPv4 address by default
(elastic/apm-server#1405).

Fixes: #3045
Refs: elastic/apm#727
github-actions bot pushed a commit to elastic/apm that referenced this issue Dec 13, 2022
…6 ambiguity (#727)

The current default APM server URL -- 'http://localhost:8200' -- is
ambiguous. "localhost" can resolve to a '127.0.0.1' (IPv4) or '[::1]'
(IPv6).

At least in Node v17 the default `dns.lookup()` ordering of results was
changed to no longer explicitly sort IPv4 addresses first.  That means
that on systems where the default resolver returns '[::1]' first for
"localhost" will result in a broken attempt to talk to a
default-configured local APM server:
  elastic/apm-agent-nodejs#3045
This is because APM server only binds to the IPv4 port:
  elastic/apm-server#1405
fpm-peter pushed a commit to fpm-git/apm-agent-nodejs that referenced this issue Aug 20, 2024
…7.0.0.1' rather than 'localhost' (elastic#3049)

Starting in node v17 the defaults for DNS resolution order was
changed (nodejs/node#39987) such that
`dns.lookup()` no longer sorted IPv4 addresses first. This impacts
usage of the *default* APM Server URL (the `serverUrl` config var),
'http://localhost:8200', when using node >=17 because the APM server
only binds to the IPv4 address by default
(elastic/apm-server#1405).

Fixes: elastic#3045
Refs: elastic/apm#727
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants