The following test fails on 0.16.0, 0.17.1, and master:
const std = @import("std");
fn noop() void {}
test {
var threaded: std.Io.Threaded = .init(std.testing.allocator, .{
.concurrent_limit = .limited(1),
});
defer threaded.deinit();
const io = threaded.io();
for (0..10_000) |i| {
var f = io.concurrent(noop, .{}) catch |err| switch (err) {
error.ConcurrencyUnavailable => |e| {
std.log.err("failed at i: {}", .{i});
return e;
},
};
defer f.cancel(io);
f.await(io);
}
}
[default] (err): failed at i: 967
1/1 test2.test_0...FAIL (ConcurrencyUnavailable)
zig/0.18.0-dev.1180+2e9bb03df/lib/std/Io/Threaded.zig:2198:9: 0x11d79fe in concurrent (std.zig)
return error.ConcurrencyUnavailable;
^
zig/0.18.0-dev.1180+2e9bb03df/lib/std/Io.zig:2620:25: 0x124c76f in concurrent__func_1011 (std.zig)
future.any_future = try io.vtable.concurrent(
^
test2.zig:16:17: 0x124c54c in test_0 (test2.zig)
return e;
^
0 passed; 0 skipped; 1 failed.
1 errors were logged.
error: the following test command failed with exit code 1:
.zig-cache/o/da7898f856eaa4da1db1a72e88d5c3bc/test --seed=0xfd24701
How do I reserve units of concurrency before I use them so I can ensure concurrency is never unavailable?
My use case is that I have an HTTP client that is repeatedly making requests to a database and I would like that client to never experience ConcurrencyUnavailable. I have already gone to great lengths reserve all its memory too… in the interest of TigerStyle.
I need timeouts on the HTTP request so I am using Io.Select with a concurrent client.fetch and concurrent sleep.
The only thing I can really do right now is set my concurrency limit extra high.