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

dns: getaddrinfo() differences between glibc and musl #2225

Open
bnoordhuis opened this issue Mar 25, 2019 · 9 comments
Open

dns: getaddrinfo() differences between glibc and musl #2225

bnoordhuis opened this issue Mar 25, 2019 · 9 comments
Assignees
Labels
enhancement not-stale Issues that should never be marked stale

Comments

@bnoordhuis
Copy link
Member

getaddrinfo() without hints defaults to:

  1. ai_flags = AI_ADDRCONFIG|AI_V4MAPPED with glibc, and
  2. ai_flags = 0 with musl libc.

That means musl by default returns addresses that may be unreachable from the current machine whereas glibc won't.

And on the flip side, glibc will return IPv4-over-IPv6 addresses if no IPv6 address for that host exists whereas musl won't.

We should probably harmonize that one way or the other but what's the preferred behavior and why?

@cjihrig
Copy link
Contributor

cjihrig commented Mar 26, 2019

This would have to be a v2 thing, right?

As a side note, if I'm remembering correctly, Node.js had a number of issues reported around using AI_ADDRCONFIG|AI_V4MAPPED by default.

@bnoordhuis
Copy link
Member Author

This would have to be a v2 thing, right?

Maybe. glibc's default seems more useful than musl's. We'd have to think through the implications but I wouldn't dismiss outright the idea of making AI_ADDRCONFIG|AI_V4MAPPED the default in v1.x.

if I'm remembering correctly, Node.js had a number of issues reported around using AI_ADDRCONFIG|AI_V4MAPPED by default.

Yes, although they weren't our bug, it was glibc's (and uclibc's, IIRC): nodejs/node#5436 (comment)

@santigimeno
Copy link
Member

Maybe. glibc's default seems more useful than musl's. We'd have to think through the implications but I wouldn't dismiss outright the idea of making AI_ADDRCONFIG|AI_V4MAPPED the default in v1.x.

I tend to agree. If we're going to set a default I would go for glibc's and tbh it seems more like a bug on our side not having the same behavior across platform, so I would vote for doing this in v1.x

@saghul
Copy link
Member

saghul commented Mar 27, 2019

I tend to agree. If we're going to set a default I would go for glibc's and tbh it seems more like a bug on our side not having the same behavior across platform, so I would vote for doing this in v1.x

+1

@stale stale bot added the stale label Aug 10, 2019
@bnoordhuis bnoordhuis removed the stale label Aug 10, 2019
@libuv libuv deleted a comment from stale bot Aug 10, 2019
@stale
Copy link

stale bot commented Nov 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 8, 2019
@santigimeno santigimeno self-assigned this Nov 8, 2019
@stale stale bot removed the stale label Nov 8, 2019
@stale
Copy link

stale bot commented Jan 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@szmarczak
Copy link

Additionally, the glibc solution assumes that loopback interfaces are routeable when their IP are different than 127.0.0.1 or ::1. With musl the logic is inverted. nodejs/node#33279 (comment)

@stale stale bot removed the stale label May 9, 2020
@stale stale bot added the stale label May 30, 2020
@bnoordhuis bnoordhuis added enhancement not-stale Issues that should never be marked stale and removed stale labels Jun 11, 2020
@libuv libuv deleted a comment from stale bot Jun 11, 2020
@SimonIremonger
Copy link

I would like to note, this musl libc6 difference seems to be problematic for busybox ntpd client, tends to end up failing to update time over IPv6....
I'm equally unclear if musl libc should be trying to read a /etc/gai.conf but, I do think, it should behave more like glibc defaults in terms of ordering responses....

@richfelker
Copy link

The glibc behavior is explicitly wrong (contrary to spec):

If hints is a null pointer, the behavior shall be as if it referred to a structure containing the value zero for the ai_flags, ai_socktype, and ai_protocol fields, and AF_UNSPEC for the ai_family field.

Further, I think libuv must be doing something badly wrong in order to get the described behavior, since (musl's) getaddrinfo sorts the results with routable ones before non-routable ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement not-stale Issues that should never be marked stale
Projects
None yet
Development

No branches or pull requests

7 participants