diff --git a/test/js/bun/http/proxy-stress-helpers.ts b/test/js/bun/http/proxy-stress-helpers.ts index 24dd0e044378..9303240e6700 100644 --- a/test/js/bun/http/proxy-stress-helpers.ts +++ b/test/js/bun/http/proxy-stress-helpers.ts @@ -365,6 +365,11 @@ export async function createAdversarialProxy(opts: AdversarialProxyOptions = {}) // and getaddrinfo want the bare literal. if (host.startsWith("[") && host.endsWith("]")) host = host.slice(1, -1); + // Origins bind 127.0.0.1 but advertise `localhost`; on darwin that + // resolves `::1` first, and v4/v6 ephemeral-port spaces are independent, + // so dial the bound address. IPv6-literal tests pass `[::1]` explicitly. + if (host === "localhost") host = "127.0.0.1"; + upstream = net.connect(port, host); let clientEnded = false; const endClient = () => {