Zig: Compile error "NetworkSubsystemFailed not handled in switch" in reading file in `io_mode = .evented`

Created on 24 Oct 2020  路  7Comments  路  Source: ziglang/zig

The code below compiles fine with Zig 0.6.0, but fails to compile with error "NetworkSubsystemFailed not handled in switch" in std/event/loop.zig, with latest master (0.6.0+91a1c20e7). (This is on Linux.)

build.zig:

const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
    var exe = b.addExecutable("x", "x.zig");
    b.default_step.dependOn(&exe.step);
}

x.zig:

pub const io_mode = .evented;
const std = @import("std");
pub fn main() !void {
    const f = try std.fs.cwd().openFile("smallfile.txt", .{});
    var buffer: [100]u8 = undefined;
    _ = try f.readAll(&buffer);
}

The compile error is

$ zig build
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/event/loop.zig:468:60: error: error.NetworkSubsystemFailed not handled in switch
                    _ = os.poll(&pfd, -1) catch |poll_err| switch (poll_err) {
                                                           ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/event/loop.zig:474:37: note: referenced here
                            std.time.sleep(1 * std.time.ns_per_ms);
                                    ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/event/loop.zig:443:39: note: referenced here
        defer if (need_to_delete) self.linuxRemoveFd(fd);
                                      ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/event/loop.zig:432:63: note: referenced here
    pub fn linuxWaitFd(self: *Loop, fd: i32, flags: u32) void {
                                                              ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/event/loop.zig:1009:49: note: when analyzing type '@Frame(std.event.loop.Loop.read)' here
                        self.waitUntilFdReadable(fd);
                                                ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/fs/file.zig:422:50: note: while checking if 'std.fs.file.File.read' is async
            return std.event.Loop.instance.?.read(self.handle, buffer, self.capable_io_mode != self.intended_io_mode);
                                                 ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/fs/file.zig:431:38: note: while checking if 'std.fs.file.File.readAll' is async
            const amt = try self.read(buffer[index..]);
                                     ^
./x.zig:6:22: note: when analyzing type '@Frame(main)' here
    _ = try f.readAll(&buffer);
                     ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/start.zig:326:37: note: while checking if 'std.start.callMain' is async
            const result = root.main() catch |err| {
                                    ^
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/lib/zig/std/start.zig:259:48: note: referenced here
            var frame: @Frame(callMainAsync) = undefined;
                                               ^
x...The following command exited with error code 1:
/home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/zig build-exe /media/marnux3data/data/projects/zig-mm/tmp/x.zig --cache-dir /media/marnux3data/data/projects/zig-mm/tmp/zig-cache --name x --enable-cache
error: the following build command failed with exit code 1:
/media/marnux3data/data/projects/zig-mm/tmp/zig-cache/o/c661213d782e893ae2ae2b6dfdeabc0e/build /home/marnix/bin/zig-linux-x86_64-0.6.0+91a1c20e7/zig /media/marnux3data/data/projects/zig-mm/tmp /media/marnux3data/data/projects/zig-mm/tmp/zig-cache
bug standard library

All 7 comments

This might have been triggered by 127fa800 in recently merged #6237.

Another reason to let std.os rot in hell (#6600), windows WSAPoll works for sockets only, while the Unix counterpart works with any kind of file.

I closed my PR #6826 in favor of #6827 which is better and also solves this issue.

@marnix Sorry for not noticing your open issue and PR! I usually look for open issues/PRs before opening one myself but I guess I was lazy yesterday.

@marnix Sorry for not noticing your open issue and PR! I usually look for open issues/PRs before opening one myself but I guess I was lazy yesterday.

No problem at all! Your PR was better at making this case unreachable, so that's why I closed mine.

Even though my PR is still undecided https://github.com/ziglang/zig/pull/6827#issuecomment-719062938, this issue can already be closed since it was fixed independently in 1b34365ca1f7222a82054ece1901ffb87ffc8b21.

Even though my PR is still undecided https://github.com/ziglang/zig/pull/6827#issuecomment-719062938, this issue can already be closed since it was fixed independently in 1b34365ca1f7222a82054ece1901ffb87ffc8b21.

Agree, double-checked that fix earlier today, closing. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewrk picture andrewrk  路  3Comments

andrewrk picture andrewrk  路  3Comments

andersfr picture andersfr  路  3Comments

jorangreef picture jorangreef  路  3Comments

andrewrk picture andrewrk  路  3Comments