MEDIA_CHANGED error on Window (network)

Hello,

I’m hitting an issue on Windows while trying to setup a local web server.

error.Unexpected NTSTATUS=0x8000001c (MEDIA_CHANGED)
C:\Users\cibrario\scoop\persist\zigup\zig\0.17.0\files\lib\std\Io\Threaded.zig:1462:40: 0x7ff775eb0509 in unexpectedNt
status (std_zcu.obj)
        return windows.unexpectedStatus(status);
                                       ^
C:\Users\cibrario\scoop\persist\zigup\zig\0.17.0\files\lib\std\Io\Threaded.zig:12732:59: 0x7ff775f3160d in openSocketA
fd (std_zcu.obj)
        else => |status| return syscall.unexpectedNtstatus(status),
                                                          ^
C:\Users\cibrario\scoop\persist\zigup\zig\0.17.0\files\lib\std\Io\Threaded.zig:12057:44: 0x7ff775f34af2 in netListenIp
Windows (std_zcu.obj)
    const socket_handle = try openSocketAfd(family, .{ .mode = options.mode, .protocol = options.protocol });
                                           ^
C:\Users\cibrario\scoop\persist\zigup\zig\0.17.0\files\lib\std\Io\net.zig:250:48: 0x7ff775fb1d9c in listen (std_zcu.ob
j)
            .socket = try io.vtable.netListenIp(io.userdata, address, options),
                                               ^
C:\Users\cibrario\scoop\persist\zigup\zig\0.17.0\files\lib\compiler\std-docs.zig:61:41: 0x7ff775f486cf in main (std_zc
u.obj)
    var http_server = try address.listen(io, .{
                                        ^

I get this for zig std as well as with the following minimal reproduction :

const std = @import("std");

pub fn main(init: std.process.Init) !void {
    const addr: std.Io.net.IpAddress = .{ .ip4 = .loopback(8080) };
    var server = try addr.listen(init.io, .{});
    defer server.deinit(init.io);
    std.log.info("ok", .{});
}

I’m pretty sure this has to do with some enterprise VPN stuff, because I’ve got this error intermittently for some time now, and I have the feeling it’s related to vpn reconnects. Sometimes rebooting the machine clears it… And of course I don’t have another window machine at hand to compare.

I know this gonna be a very annoying reproduction, but wanted to know is anybody familiar with this or has encounter similar issue ?

I cannot reproduce it on Windows 11 (26H2 build 26300.9711); I am getting the expected: info: ok
I using zig version 0.17.0; installed with winget install zig.zig

Some ideas:

  • Try another port (8080 might be in use or blocked)
  • Try to disable: Firewall, VPN, Antivirus.

Thanks for taking the time to trying it out.

But as I said, it’s a transient behavior (albeit one that can persist for hours, up to the next reboot or sometimes more - I failed to identify the cause of both the apparition and disparition of the issue)

Did try to disable the VPN, but I don’t have full network control on this company laptop.

Also, forgot to mention it in the previous message, but it’s not a matter of busy port, because python -m http.server on the same port works without issues.

Anyways, the issue was more about somebody being familiar with the underlying Window error code. I’m not convinced zig is handling this error the optimal way (by wrapping it in “Unexpected”). Or more precisely that I suspect it’s a condition that we should be able to recover from somehow. But I’m not familiar with Windows APIs the slightest, hence the question.