aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-14 01:26:39 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-14 01:26:39 -0700
commit4638871050f8658f1a0b7b0bab40cedf90cc932f (patch)
tree8c9d47f16f782478524af249788828b9a04ba668 /src
parent13cd18e614a6d2519da43c4165a2e5ae9128b349 (diff)
downloadbun-4638871050f8658f1a0b7b0bab40cedf90cc932f.tar.gz
bun-4638871050f8658f1a0b7b0bab40cedf90cc932f.tar.zst
bun-4638871050f8658f1a0b7b0bab40cedf90cc932f.zip
[bun dev] Fix crash on macOS
Diffstat (limited to 'src')
-rw-r--r--src/http.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/http.zig b/src/http.zig
index 2e1f153c0..9258af461 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -83,6 +83,16 @@ const SOCKET_FLAGS: u32 = if (Environment.isLinux)
else
os.SOCK.CLOEXEC;
+fn disableSIGPIPESoClosingTheTabDoesntCrash(conn: anytype) void {
+ if (comptime !Environment.isMac) return;
+ std.os.setsockopt(
+ conn.client.socket.fd,
+ std.os.SOL.SOCKET,
+ std.os.SO.NOSIGPIPE,
+ &std.mem.toBytes(@as(c_int, 1)),
+ ) catch {};
+}
+
pub const RequestContext = struct {
request: Request,
method: Method,
@@ -3636,6 +3646,8 @@ pub const Server = struct {
var conn = listener.accept(.{ .close_on_exec = true }) catch
continue;
+ disableSIGPIPESoClosingTheTabDoesntCrash(conn);
+
// We want to bind to the network socket as quickly as possible so that opening the URL works
// We use a secondary loop so that we avoid the extra branch in a hot code path
Analytics.Features.fast_refresh = server.bundler.options.jsx.supports_fast_refresh;
@@ -3653,6 +3665,8 @@ pub const Server = struct {
var conn = listener.accept(.{ .close_on_exec = true }) catch
continue;
+ disableSIGPIPESoClosingTheTabDoesntCrash(conn);
+
server.handleConnection(&conn, comptime features);
}
}