mitchellh / libxev

libxev is a cross-platform, high-performance event loop that provides abstractions for non-blocking IO, timers, events, and more and works on Linux (io_uring or epoll), macOS (kqueue), and Wasm + WASI. Available as both a Zig and C API.
MIT License
2.07k stars 74 forks source link

Handle EAGAIN errno's properly #35

Closed RossComputerGuy closed 1 year ago

RossComputerGuy commented 1 year ago

When working on a project, I wanted to see if setting NONBLOCK would allow for the thread to shutdown if the loop is stopped. I enabled it and got errno 11 which is EAGAIN. I think libxev should handle this error and just continue to monitor until the next event. This would make it so developers using libxev won't have to catch this error on their own.

neutron.runtime.ipc.base.Ipc{ .server = neutron.runtime.ipc.base.server{ .type = neutron.elemental.type.Type(neutron.runtime.ipc.base.server,neutron.runtime.ipc.base.server.Params,neutron.runtime.ipc.base.server.Impl){ .allocated = false, .allocator = mem.Allocator{ ... }, .parent = anyopaque@7ffc7e50dc80, .ref = neutron.elemental.ref{ ... } }, .base = neutron.runtime.ipc.base.base{ .type = neutron.elemental.type.Type(neutron.runtime.ipc.base.base,neutron.runtime.ipc.base.base.Params,neutron.runtime.ipc.base.base.Impl){ ... }, .vtable = neutron.runtime.ipc.base.base.VTableunexpected errno: { ... }, .runtime11 =
neutron.runtime.runtime{ ... }, .loop = backend.io_uring.Loop{ ... }, .running = false, .thread = null } } }/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/debug.zig:561:19: 0x2939a7 in writeCurrentStackTrace__anon_10812 (neutron-runner)
    while (it.next()) |return_address| {
                  ^
/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/debug.zig:157:80: 0x257b8d in dumpCurrentStackTrace (neutron-runner)
        writeCurrentStackTrace(stderr, debug_info, detectTTYConfig(io.getStdErr()), start_addr) catch |err| {
                                                                               ^
/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/os.zig:5559:40: 0x23c438 in unexpectedErrno (neutron-runner)
        std.debug.dumpCurrentStackTrace(null);
                                       ^
/home/ross/ExpidusOS/neutron/vendor/third-party/zig/libxev/src/backend/io_uring.zig:557:59: 0x25bb33 in invoke (neutron-runner)
                    else => |errno| std.os.unexpectedErrno(errno),
                                                          ^
/home/ross/ExpidusOS/neutron/vendor/third-party/zig/libxev/src/backend/io_uring.zig:147:43: 0x25d408 in tick___anon_8624 (neutron-runner)
                switch (c.invoke(self, cqe.res)) {
                                          ^
/home/ross/ExpidusOS/neutron/vendor/third-party/zig/libxev/src/backend/io_uring.zig:60:42: 0x25d5b0 in run (neutron-runner)
            .until_done => try self.tick_(.until_done),
                                         ^
/home/ross/ExpidusOS/neutron/src/neutron/runtime/ipc/base/base.zig:75:24: 0x25d618 in callback (neutron-runner)
      try base.loop.run(.until_done);
                       ^
/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/Thread.zig:427:13: 0x296166 in callFn__anon_10930 (neutron-runner)
            @call(.auto, f, args) catch |err| {
            ^
/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/Thread.zig:679:30: 0x25de5c in entryFn (neutron-runner)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x7f9e6c40be85 in ??? (???)
thread 2996945 panic: attempt to unwrap error: Unexpected
/home/ross/ExpidusOS/neutron/src/neutron/runtime/ipc/socket/server.zig:93:37: 0x241d23 in callback (neutron-runner)
        const fd = res.accept catch unreachable;
                                    ^
/home/ross/ExpidusOS/neutron/vendor/third-party/zig/libxev/src/backend/io_uring.zig:671:34: 0x25c7ac in invoke (neutron-runner)
        return self.callback(self.userdata, loop, self, result);
                                 ^
/home/ross/ExpidusOS/neutron/vendor/third-party/zig/libxev/src/backend/io_uring.zig:147:43: 0x25d408 in tick___anon_8624 (neutron-runner)
                switch (c.invoke(self, cqe.res)) {
                                          ^
/home/ross/ExpidusOS/neutron/vendor/third-party/zig/libxev/src/backend/io_uring.zig:60:42: 0x25d5b0 in run (neutron-runner)
            .until_done => try self.tick_(.until_done),
                                         ^
/home/ross/ExpidusOS/neutron/src/neutron/runtime/ipc/base/base.zig:75:24: 0x25d618 in callback (neutron-runner)
      try base.loop.run(.until_done);
                       ^
/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/Thread.zig:427:13: 0x296166 in callFn__anon_10930 (neutron-runner)
            @call(.auto, f, args) catch |err| {
            ^
/nix/store/vxhdcs2nc56ynlkm89f6f0qndsk5rs36-zig-0.11.0-dev.2247+38ee46dda/lib/std/Thread.zig:679:30: 0x25de5c in entryFn (neutron-runner)
                return callFn(f, args_ptr.*)