Zig Version
0.16.0-dev.2821+3edaef9e0
Steps to Reproduce and Observed Behavior
Here's a minimal example that works on linux, but hangs on windows. The issue is the cancelDiscard that runs on defer.
Might not be the intended way to timeout a task.
As a side note, when i tested this with a stdin reader, this works on windows. Seems to be net handling that is the issue.
const std = @import("std");
const Io = std.Io;
const net = Io.net;
pub fn main(init: std.process.Init) !void {
const io = init.io;
const address: net.IpAddress = .{ .ip4 = try net.Ip4Address.parse("127.0.0.1", 19876) };
// create server
var server = try address.listen(io, .{ .mode = .stream, .protocol = .tcp, .reuse_address = true });
defer server.deinit(io);
// connect client
const stream = try address.connect(io, .{ .mode = .stream, .protocol = .tcp });
defer stream.close(io);
// read from client
var buf: [64]u8 = undefined;
var reader = stream.reader(io, &buf);
// 100ms timeout
const timeout: Io.Timeout = .{ .duration = .{
.raw = Io.Duration.fromMilliseconds(100),
.clock = .awake,
} };
const Result = union(enum) {
read: Io.Cancelable!void,
timeout: Io.Cancelable!void,
};
var selbuf: [2]Result = undefined;
var sel = Io.Select(Result).init(io, &selbuf);
// this is the problem on windows - hangs
defer sel.cancelDiscard();
try sel.concurrent(.read, peekByte, .{&reader.interface});
try sel.concurrent(.timeout, Io.Timeout.sleep, .{ timeout, io });
_ = try sel.await();
}
fn peekByte(r: *Io.Reader) Io.Cancelable!void {
_ = r.peekByte() catch return Io.Cancelable.Canceled;
}
Expected Behavior
I would expect the peekByte function to get cancelled and the program would stop after ~100ms
### Zig Version
0.16.0-dev.2821+3edaef9e0
### Steps to Reproduce and Observed Behavior
Here's a minimal example that works on linux, but hangs on windows. The issue is the cancelDiscard that runs on defer.
Might not be the intended way to timeout a task.
As a side note, when i tested this with a stdin reader, this works on windows. Seems to be net handling that is the issue.
```
const std = @import("std");
const Io = std.Io;
const net = Io.net;
pub fn main(init: std.process.Init) !void {
const io = init.io;
const address: net.IpAddress = .{ .ip4 = try net.Ip4Address.parse("127.0.0.1", 19876) };
// create server
var server = try address.listen(io, .{ .mode = .stream, .protocol = .tcp, .reuse_address = true });
defer server.deinit(io);
// connect client
const stream = try address.connect(io, .{ .mode = .stream, .protocol = .tcp });
defer stream.close(io);
// read from client
var buf: [64]u8 = undefined;
var reader = stream.reader(io, &buf);
// 100ms timeout
const timeout: Io.Timeout = .{ .duration = .{
.raw = Io.Duration.fromMilliseconds(100),
.clock = .awake,
} };
const Result = union(enum) {
read: Io.Cancelable!void,
timeout: Io.Cancelable!void,
};
var selbuf: [2]Result = undefined;
var sel = Io.Select(Result).init(io, &selbuf);
// this is the problem on windows - hangs
defer sel.cancelDiscard();
try sel.concurrent(.read, peekByte, .{&reader.interface});
try sel.concurrent(.timeout, Io.Timeout.sleep, .{ timeout, io });
_ = try sel.await();
}
fn peekByte(r: *Io.Reader) Io.Cancelable!void {
_ = r.peekByte() catch return Io.Cancelable.Canceled;
}
```
### Expected Behavior
I would expect the peekByte function to get cancelled and the program would stop after ~100ms