mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix error from requesting too much from io_uring
This commit is contained in:
@@ -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(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 }),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user