aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/http/network_thread.zig14
-rw-r--r--src/io/io_darwin.zig2
-rw-r--r--src/io/io_linux.zig20
3 files changed, 32 insertions, 4 deletions
diff --git a/src/http/network_thread.zig b/src/http/network_thread.zig
index d3826dcb3..0ae0fce5f 100644
--- a/src/http/network_thread.zig
+++ b/src/http/network_thread.zig
@@ -3,6 +3,7 @@ pub const Batch = ThreadPool.Batch;
pub const Task = ThreadPool.Task;
const std = @import("std");
const AsyncIO = @import("io");
+const Output = @import("../global.zig").Output;
const NetworkThread = @This();
@@ -70,8 +71,19 @@ pub fn getAddressList(allocator: *std.mem.Allocator, name: []const u8, port: u16
pub fn init() !void {
if ((global_loaded.swap(1, .Monotonic)) == 1) return;
+ AsyncIO.global = AsyncIO.init(1024, 0) catch |err| {
+ Output.prettyErrorln("<r><red>error<r>: Failed to initialize network thread: <red><b>{s}<r>.\nHTTP requests will not work. Please file an issue and run strace().", .{@errorName(err)});
+ Output.flush();
+
+ global = NetworkThread{
+ .pool = ThreadPool.init(.{ .max_threads = 0, .stack_size = 64 * 1024 * 1024 }),
+ };
+ global.pool.max_threads = 0;
+ AsyncIO.global_loaded = true;
+ return;
+ };
+
AsyncIO.global_loaded = true;
- AsyncIO.global = try AsyncIO.init(1024, 0);
global = NetworkThread{
.pool = ThreadPool.init(.{ .max_threads = 1, .stack_size = 64 * 1024 * 1024 }),
diff --git a/src/io/io_darwin.zig b/src/io/io_darwin.zig
index 2042a38ea..6d77878d2 100644
--- a/src/io/io_darwin.zig
+++ b/src/io/io_darwin.zig
@@ -31,7 +31,7 @@ completed: FIFO(Completion) = .{},
io_pending: FIFO(Completion) = .{},
last_event_fd: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(32),
-pub fn init(entries: u12, flags: u32) !IO {
+pub fn init(_: u12, _: u32) !IO {
const kq = try os.kqueue();
assert(kq > -1);
return IO{ .kq = kq };
diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig
index f69f70c5b..b22dc92a5 100644
--- a/src/io/io_linux.zig
+++ b/src/io/io_linux.zig
@@ -62,8 +62,24 @@ unqueued: FIFO(Completion) = .{},
/// Completions that are ready to have their callbacks run.
completed: FIFO(Completion) = .{},
-pub fn init(entries: u12, flags: u32) !IO {
- return IO{ .ring = try IO_Uring.init(entries, flags) };
+pub fn init(entries_: u12, flags: u32) !IO {
+ var ring: IO_Uring = undefined;
+ var entries = entries_;
+ while (true) {
+ ring = IO_Uring.init(entries, flags) catch |err| {
+ if (err == error.SystemResources) {
+ if (entries < 4) return error.SystemResources;
+ entries /= 2;
+ continue;
+ }
+
+ return err;
+ };
+ break;
+ }
+
+
+ return IO{ .ring = ring };
}
pub fn deinit(self: *IO) void {