Skip to content

Inconsistent IP version preference in Bun node:dns.lookup #29227

@kevgeoleo

Description

@kevgeoleo

What version of Bun is running?

1.3.11-canary.1+9e93bfa1b

What platform is your computer?

Linux 5.10.0-12-amd64 x86_64 x86_64

What steps can reproduce the bug?

Hi,

I would like to report a behavior in Bun that can be reproduced using the below snippet:

import dns from "node:dns";

console.log("Starting DNS lookup for mongo-1...");

dns.lookup("mongo-1", (err, address, family) => {
  console.error("lookup callback error:", err);
  console.log("address: %j family: IPv%s", address, family);
  process.exit(err ? 1 : 0);
});

What is the expected behavior?

root@KContainer:~/25927# node dns_lookup.mjs
Starting DNS lookup for mongo-1...
lookup callback error: null
address: "127.0.0.1" family: IPv4
root@KContainer:~/25927# deno run -A dns_lookup.mjs
Starting DNS lookup for mongo-1...
lookup callback error: null
address: "127.0.0.1" family: IPv4

What do you see instead?

dns.lookup("mongo-1") resolves to 127.0.0.1 in Node and Deno, but returns ::1 in Bun.
This causes behavior differences in code

root@KContainer:~/25927# bun run dns_lookup.mjs
Starting DNS lookup for mongo-1...
lookup callback error: null
address: "::1" family: IPv6

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions