Always make sure we have 1 free http state available for synchronous requests

If it wasn't for the fact that the HTTP client is likely going to see a major
refactor, it would definitely be time to create a specific state instance for
synchronous requests.
This commit is contained in:
Karl Seguin
2025-07-14 16:41:26 +08:00
parent d35a3eab6c
commit 4f8a3fe5b9

View File

@@ -287,6 +287,12 @@ const AsyncQueue = struct {
fn _check(self: *AsyncQueue, repeat_delay: *?u63) !void { fn _check(self: *AsyncQueue, repeat_delay: *?u63) !void {
const client = self.client; const client = self.client;
if (client.freeSlotCount() == 1) {
// always leave 1 free connection for sync requests
repeat_delay.* = 10 * std.time.ns_per_ms;
return;
}
const state = client.state_pool.acquireOrNull() orelse { const state = client.state_pool.acquireOrNull() orelse {
// re-run this function in 10 milliseconds // re-run this function in 10 milliseconds
repeat_delay.* = 10 * std.time.ns_per_ms; repeat_delay.* = 10 * std.time.ns_per_ms;
@@ -3802,7 +3808,7 @@ const TestContext = struct {
errdefer loop.deinit(); errdefer loop.deinit();
var o = opts; var o = opts;
o.max_concurrent = 1; o.max_concurrent = 2;
const client = try Client.init(testing.allocator, loop, o); const client = try Client.init(testing.allocator, loop, o);
errdefer client.deinit(); errdefer client.deinit();