Spot the bug in the DNS endpoint lookup

from DNS resolution
Node 24 intermediate 8 min 3 issues to find

Find the DNS correctness bugs in this generated endpoint lookup.

JavaScript
import { promises as dns } from "node:dns";

const cache = new Map();

export async function endpoint(hostname) {
  if (cache.has(hostname)) return cache.get(hostname);
  try {
    const [address] = await dns.resolve4(hostname);
    cache.set(hostname, address);
    return address;
  } catch {
    return null;
  }
}
Open in playground
Report an error