From db7d954a503a19aa4b3a31cca24db2c55604db71 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sat, 7 Mar 2026 20:33:27 +0100 Subject: [PATCH] fix: automatically bump the kqueue file limit to the hard limit --- src/nightwatch.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/nightwatch.zig b/src/nightwatch.zig index 31550c8..8dfdae0 100644 --- a/src/nightwatch.zig +++ b/src/nightwatch.zig @@ -538,6 +538,13 @@ const KQueueBackend = struct { const NOTE_RENAME: u32 = 0x00000020; fn init(handler: *Handler) (std.posix.KQueueError || std.posix.KEventError)!@This() { + // Per-file kqueue watches require one open fd per watched file. Bump + // the soft NOFILE limit to the hard limit so large directory trees don't + // exhaust the default quota (256 on macOS, 1024 on many FreeBSD installs). + if (std.posix.getrlimit(.NOFILE)) |rl| { + if (rl.cur < rl.max) + std.posix.setrlimit(.NOFILE, .{ .cur = rl.max, .max = rl.max }) catch {}; + } else |_| {} const kq = try std.posix.kqueue(); errdefer std.posix.close(kq); const pipe = try std.posix.pipe();