diff options
author | 2022-04-11 05:17:02 -0700 | |
---|---|---|
committer | 2022-04-11 05:17:02 -0700 | |
commit | 4708dd26cac2a3c0f5fac740252cbe5b51e77a79 (patch) | |
tree | 81607f71a4a20888857020a3a0427003457eea6a /src/http/async_socket.zig | |
parent | 3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6 (diff) | |
download | bun-4708dd26cac2a3c0f5fac740252cbe5b51e77a79.tar.gz bun-4708dd26cac2a3c0f5fac740252cbe5b51e77a79.tar.zst bun-4708dd26cac2a3c0f5fac740252cbe5b51e77a79.zip |
work around fetch("localhost") bug
Diffstat (limited to 'src/http/async_socket.zig')
-rw-r--r-- | src/http/async_socket.zig | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/http/async_socket.zig b/src/http/async_socket.zig index bdfee7412..3cf25944b 100644 --- a/src/http/async_socket.zig +++ b/src/http/async_socket.zig @@ -116,7 +116,7 @@ pub fn connect(this: *AsyncSocket, name: []const u8, port: u16) ConnectError!voi this.was_keepalive = false; return try this.doConnect(name, port); } - +const strings = @import("strings"); fn doConnect(this: *AsyncSocket, name: []const u8, port: u16) ConnectError!void { this.was_keepalive = false; @@ -129,7 +129,20 @@ fn doConnect(this: *AsyncSocket, name: []const u8, port: u16) ConnectError!void // on macOS, getaddrinfo() is very slow // If you send ~200 network requests, about 1.5s is spent on getaddrinfo() // So, we cache this. - var list = NetworkThread.getAddressList(allocator, name, port) catch |err| { + var list = NetworkThread.getAddressList( + allocator, + // There is a bug where getAddressList always fails on localhost + // I don't understand why + // but 127.0.0.1 works + // so we can just use that + // this is technically incorrect – one could remap localhost to something other than 127.0.0.1 + // but we will wait for someone to complain about it before addressing it + if (!strings.eqlComptime(name, "localhost")) + name + else + "127.0.0.1", + port, + ) catch |err| { return @errSetCast(ConnectError, err); }; |