aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/api/bun/socket.zig13
-rw-r--r--test/bun.js/socket/echo.js42
-rw-r--r--test/bun.js/socket/socket.test.ts2
3 files changed, 37 insertions, 20 deletions
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig
index 7e0f0ec4e..329a6bbed 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -460,7 +460,18 @@ pub const Listener = struct {
.host => |c| {
var host = bun.default_allocator.dupeZ(u8, c.host) catch unreachable;
defer bun.default_allocator.destroy(host.ptr);
- this.listener = uws.us_socket_context_listen(@boolToInt(ssl_enabled), this.socket_context, host, c.port, socket_flags, 8) orelse {
+ this.listener = uws.us_socket_context_listen(
+ @boolToInt(ssl_enabled),
+ this.socket_context,
+ // workaround issue with IPv6 localhost with getaddrinfo()
+ if (strings.eqlComptime(c.host, "localhost"))
+ "127.0.0.1"
+ else
+ host,
+ c.port,
+ socket_flags,
+ 8,
+ ) orelse {
exception.* = JSC.toInvalidArguments(
"Failed to listen at {s}:{d}",
.{
diff --git a/test/bun.js/socket/echo.js b/test/bun.js/socket/echo.js
index e864f1b2b..40acd631c 100644
--- a/test/bun.js/socket/echo.js
+++ b/test/bun.js/socket/echo.js
@@ -1,24 +1,28 @@
function createOptions(type, message, closeOnDone) {
let buffers = [];
- let report = function() {
- report = function() {};
- const data = new Uint8Array(buffers.reduce(function(sum, buffer) {
- return sum + buffer.length;
- }, 0));
- buffers.reduce(function(offset, buffer) {
+ let report = function () {
+ report = function () {};
+ const data = new Uint8Array(
+ buffers.reduce(function (sum, buffer) {
+ return sum + buffer.length;
+ }, 0),
+ );
+ buffers.reduce(function (offset, buffer) {
data.set(buffer, offset);
return offset + buffer.length;
}, 0);
console.log(type, "GOT", new TextDecoder().decode(data));
- }
+ };
- let done = closeOnDone ? function(socket, sent) {
- socket.data[sent ? "sent" : "received"] = true;
- if (socket.data.sent && socket.data.received) {
- done = function() {};
- closeOnDone(socket);
- }
- } : function() {};
+ let done = closeOnDone
+ ? function (socket, sent) {
+ socket.data[sent ? "sent" : "received"] = true;
+ if (socket.data.sent && socket.data.received) {
+ done = function () {};
+ closeOnDone(socket);
+ }
+ }
+ : function () {};
function drain(socket) {
const message = socket.data.message;
@@ -63,8 +67,10 @@ function createOptions(type, message, closeOnDone) {
};
}
-const server = Bun.listen(createOptions("[Server]", "response", socket => {
- server.stop();
- socket.end();
-}));
+const server = Bun.listen(
+ createOptions("[Server]", "response", (socket) => {
+ server.stop();
+ socket.end();
+ }),
+);
Bun.connect(createOptions("[Client]", "request"));
diff --git a/test/bun.js/socket/socket.test.ts b/test/bun.js/socket/socket.test.ts
index 28c945f64..f9218493f 100644
--- a/test/bun.js/socket/socket.test.ts
+++ b/test/bun.js/socket/socket.test.ts
@@ -37,7 +37,7 @@ it("should reject on connection error, calling both connectError() and rejecting
var data = {};
connect({
data,
- hostname: "127.0.0.1",
+ hostname: "localhost",
port: 55555,
socket: {
connectError(socket, error) {