From 4f8a3fe5b9de24cdd011b6f3f1fc0219a9e696a8 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Mon, 14 Jul 2025 16:41:26 +0800 Subject: [PATCH] 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. --- src/http/client.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/http/client.zig b/src/http/client.zig index 41f432a6..3b993929 100644 --- a/src/http/client.zig +++ b/src/http/client.zig @@ -287,6 +287,12 @@ const AsyncQueue = struct { fn _check(self: *AsyncQueue, repeat_delay: *?u63) !void { 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 { // re-run this function in 10 milliseconds repeat_delay.* = 10 * std.time.ns_per_ms; @@ -3802,7 +3808,7 @@ const TestContext = struct { errdefer loop.deinit(); var o = opts; - o.max_concurrent = 1; + o.max_concurrent = 2; const client = try Client.init(testing.allocator, loop, o); errdefer client.deinit();