undici icon indicating copy to clipboard operation
undici copied to clipboard

Try all available addresses when connecting to localhost (127.0.0.1 and ::1)

Open mcollina opened this issue 2 years ago • 4 comments

In node v17 (specifically https://github.com/nodejs/node/pull/39987), we switched the default ordering of dns entries to follow what the OS is providing us vs reordering to put IPv4 addresses always first. This creates quite a few issues for folks as some tools only listen to 127.0.0.1 and not ::1.

I think we should try multiple addresses when dealing with localhost when establishing a new connection.

Originaklly reported as https://github.com/nodejs/undici/issues/1248.

mcollina avatar Aug 16 '22 13:08 mcollina

I don't quite understand what localhost has to do with this issue? In #1248 no localhost was involved.

kyrylkov avatar Aug 16 '22 13:08 kyrylkov

This issue is based on this comment: https://github.com/nodejs/undici/issues/1248#issuecomment-1054467140. There is something we could improve with localhost. As for your problem, we need a repro (feel free to add it to the original issue).

mcollina avatar Aug 16 '22 13:08 mcollina

FWIW I'm getting this when running mockAgent.disableNetConnect() with fetch. Might be a different issue (including an "I'm holding it wrong" issue), but wanted to let y'all know just in case. Here's my monorepo (core is the module that matters here) at the commit that I'm consistently experiencing this issue with.

I think this should work as a way to get the stack traces quickly: git clone https://github.com/cutenode/nodevu && cd nodevu && git checkout 38d46bee90cd0d20762257f9aa6c99ef9ed341ae && npm install && npm run test -w core

bnb avatar Sep 14 '22 18:09 bnb

Note: this is better solved in nodejs core. https://github.com/nodejs/node/issues/41625

mcollina avatar Sep 14 '22 18:09 mcollina

Hi @mcollina, seems like this haven't been assigned/implemented yet?

jodevsa avatar Nov 26 '22 14:11 jodevsa

would this fix https://github.com/nodejs/node/pull/44731 solve this issue?

jodevsa avatar Nov 26 '22 14:11 jodevsa

Yes, we'd need to enable that setting once it lands.

mcollina avatar Nov 26 '22 18:11 mcollina

Should we enable it by default? Agents should be able to set this option already, under connect in options.

KhafraDev avatar Dec 03 '22 19:12 KhafraDev