getaddrinfo() without hints defaults to:
ai_flags = AI_ADDRCONFIG|AI_V4MAPPED with glibc, andai_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?
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.
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): https://github.com/nodejs/node/issues/5436#issuecomment-189474356
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
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
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.
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.
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. https://github.com/nodejs/node/issues/33279#issuecomment-626138286
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....
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.
Most helpful comment
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