Skip to content

Commit

Permalink
Fix error from requesting too much from io_uring
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Dec 23, 2021
1 parent 3285346 commit 2cfdf29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/http/network_thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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(512, 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 }),
Expand Down
20 changes: 18 additions & 2 deletions src/io/io_linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2cfdf29

Please sign in to comment.