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

Upgrade an app to Node 18 breaks APM with the default configuration #3045

Closed
1 of 3 tasks
ddolcimascolo opened this issue Nov 25, 2022 · 5 comments · Fixed by #3049
Closed
1 of 3 tasks

Upgrade an app to Node 18 breaks APM with the default configuration #3045

ddolcimascolo opened this issue Nov 25, 2022 · 5 comments · Fixed by #3049
Assignees
Labels
agent-nodejs Make available for APM Agents project planning. community

Comments

@ddolcimascolo
Copy link
Contributor

ddolcimascolo commented Nov 25, 2022

Describe the bug

Under Node 18, on a system with ipv6 enabled, localhost resolves to ::1 (the ipv6 address) while under Node <= 16 it resolved to 127.0.0.1 (the ipv4 address). Considering that APM server listens on the ipv4 address only in these conditions if using the default configuration (as per elastic/apm-server#1405), upgrading an application using this agent from Node 16 to Node 18 (now that Node 18 is LTS) will prevent APM from working because the agent defaults serverUrl to http://localhost:8200.

To Reproduce

Upgrade an existing app using this agent to Node 18.

Expected behavior

APM keeps on working fine after the Node upgrade.

Environment (please complete the following information)

  • OS: Ubuntu 22.04
  • Node.js version: 18
  • APM Server version: 8.5.1
  • Agent version: Latest

How are you starting the agent? (please tick one of the boxes)

  • Calling agent.start() directly (e.g. require('elastic-apm-node').start(...))
  • Requiring elastic-apm-node/start from within the source code
  • Starting node with -r elastic-apm-node/start

Additional context

Suggested fix: Default serverUrl to http://127.0.0.1:8200

@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Nov 25, 2022
@ddolcimascolo
Copy link
Contributor Author

For the record, simply configuring the agent to connect to http://127.0.0.1:8200 fixes the problem. I'm personnaly using the environment variable ELASTIC_APM_SERVER_URL=http://127.0.0.1:8200

@ddolcimascolo
Copy link
Contributor Author

Reference to the change in NodeJS: nodejs/node#39987

trentm added a commit 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
Copy link
Member

trentm commented Nov 28, 2022

Agreed on changing the default as you suggest. Thanks for this issue, @ddolcimascolo!

I actually ran into the same basic issue earlier when adding support for Node v17 here: #2380 (comment)
and I learned of the Node.js dns.lookup behaviour change on this issue: nodejs/node#40537

However, I hadn't made the logical leap that this would break usage of the APM agents usage of 'localhost' for the serverUrl config var.

I still have some changes to add to my PR. I likely won't get a release out for about a week.

@trentm
Copy link
Member

trentm commented Nov 28, 2022

Side note: Recently supported Lambda Node v18 containers not currently affected. With this handler code:

  dns.lookup('localhost', {all: true}, (err, results) => {
      console.log('XXX dns.lookup(localhost) results:', results)
  })

the result is:

2022-11-28T23:25:30.105000+00:00 2022/11/28/[$LATEST]9e3e3d9871304fa9b4c399485d4a4618 2022-11-28T23:25:30.105Z	5a0afd7a-e206-4b18-9a0f-93dcc90b36e9	INFO	XXX dns.lookup(localhost) results: [ { address: '127.0.0.1', family: 4 }, { address: '::1', family: 6 } ]

I.e. the IPv4 "localhost" result is first. I.e. the system resolver is returning the IPv4 address first.

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
@ddolcimascolo
Copy link
Contributor Author

Thx for fixing @trentm!

trentm added a commit 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
@trentm trentm removed the triage label Dec 8, 2022
@trentm trentm self-assigned this Dec 8, 2022
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
agent-nodejs Make available for APM Agents project planning. community
Projects
None yet
2 participants