From afde88796246ed015f32daac3576ed92a1d8049c Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Tue, 4 Nov 2025 22:48:00 +0100 Subject: [PATCH 1/2] fixing the udp cancelation when canceled the ip adress construction would reach unreachable code because the addr buffer was uninitialized Signed-off-by: Jakub Doka --- src/watcher/udp.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/watcher/udp.zig b/src/watcher/udp.zig index 7df3ab1..358c866 100644 --- a/src/watcher/udp.zig +++ b/src/watcher/udp.zig @@ -130,7 +130,10 @@ fn UDPSendto(comptime xev: type) type { l_inner, c_inner, s_inner, - std.net.Address.initPosix(@alignCast(&c_inner.op.recvfrom.addr)), + // cancelation can cause this to be uninitialized + if (r.recvfrom) |_| std.net.Address.initPosix( + @alignCast(&c_inner.op.recvfrom.addr), + ) else |_| undefined, initFd(c_inner.op.recvfrom.fd), c_inner.op.recvfrom.buffer, r.recvfrom, @@ -308,7 +311,10 @@ fn UDPSendtoIOCP(comptime xev: type) type { l_inner, c_inner, s_inner, - std.net.Address.initPosix(@alignCast(&c_inner.op.recvfrom.addr)), + // cancelation can cause this to be uninitialized + if (r.recvfrom) |_| std.net.Address.initPosix( + @alignCast(&c_inner.op.recvfrom.addr), + ) else |_| undefined, initFd(c_inner.op.recvfrom.fd), c_inner.op.recvfrom.buffer, r.recvfrom, @@ -540,7 +546,10 @@ fn UDPSendMsg(comptime xev: type) type { l_inner, c_inner, s_inner, - std.net.Address.initPosix(@ptrCast(&s_inner.op.recv.addr_buffer)), + // cancelation can cause this to be uninitialized + if (r.recvmsg) |_| std.net.Address.initPosix( + @ptrCast(&s_inner.op.recv.addr_buffer), + ) else |_| undefined, initFd(c_inner.op.recvmsg.fd), s_inner.op.recv.buf, if (r.recvmsg) |v| v else |err| err, From ac07fb03f9f0e83382308560ae515745b70284ba Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 15 Nov 2025 16:23:47 +0100 Subject: [PATCH 2/2] fixed windows deadlock Signed-off-by: Jakub Doka --- src/backend/iocp.zig | 9 ++++++++- src/watcher/udp.zig | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/iocp.zig b/src/backend/iocp.zig index 671d08c..c2d3bbb 100644 --- a/src/backend/iocp.zig +++ b/src/backend/iocp.zig @@ -259,6 +259,7 @@ pub const Loop = struct { // Process the completions we already have completed. while (self.completions.pop()) |c| { + std.debug.print("whu\n", .{}); // We store whether this completion was active so we can decrement the active count // later. const c_active = c.flags.state == .active; @@ -282,6 +283,7 @@ pub const Loop = struct { // Process asyncs if (!self.asyncs.empty()) { + std.debug.print("whu\n", .{}); var asyncs = self.asyncs; self.asyncs = .{}; @@ -310,10 +312,15 @@ pub const Loop = struct { } // If we have processed enough event, we break out of the loop. - if (wait_rem == 0) break; + // + // We continue with timeout 0 if this ins nonblocking otherwise + // nothing gets done if user only does .no_wait. + if (wait_rem == 0 and wait != 0) break; // Determine our next timeout based on the timers. const timeout: ?windows.DWORD = timeout: { + if (wait == 0) break :timeout 0; + // If we have a timer, we want to set the timeout to our next timer value. If we // have no timer, we wait forever. const t = self.timers.peek() orelse break :timeout null; diff --git a/src/watcher/udp.zig b/src/watcher/udp.zig index 358c866..fa1d25c 100644 --- a/src/watcher/udp.zig +++ b/src/watcher/udp.zig @@ -547,7 +547,9 @@ fn UDPSendMsg(comptime xev: type) type { c_inner, s_inner, // cancelation can cause this to be uninitialized - if (r.recvmsg) |_| std.net.Address.initPosix( + if (r.recvmsg) |_| if (s_inner.op.recv.addr_buffer.family == 0xaaaa) b: { + break :b undefined; + } else std.net.Address.initPosix( @ptrCast(&s_inner.op.recv.addr_buffer), ) else |_| undefined, initFd(c_inner.op.recvmsg.fd),