Treat pending requests as active

This ensures that page.wait won't unblock too early. As-is, this isn't an issue
since active can only be 0 if there are no active OR pending requests. However,
with request interception (https://github.com/lightpanda-io/browser/pull/930)
it's possible to have no active requests and no pending requests - from the
http client's point of view - but still have pending-on-intercept requests.

An alternative to this would be to undo these changes, and instead change
Page.wait to be intercept-aware. That is, Page.wait would continue to block on
http activity and scheduled tasks, as well as intercepted requests. However,
since the Page doesn't know anything about CDP right now, and it does know
about the http client, maybe doing this in the client is fine.
This commit is contained in:
Karl Seguin
2025-08-12 11:13:19 +08:00
parent 05192b6850
commit 19c908035b
2 changed files with 13 additions and 4 deletions

View File

@@ -185,12 +185,14 @@ pub fn tick(self: *Client, timeout_ms: usize) !void {
pub fn request(self: *Client, req: Request) !void {
if (self.handles.getFreeHandle()) |handle| {
self.active += 1;
return self.makeRequest(handle, req);
}
const node = try self.queue_node_pool.create();
node.data = req;
self.queue.append(node);
self.active += 1;
}
// See ScriptManager.blockingGet
@@ -234,13 +236,18 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
// we need this for cookies
const uri = std.Uri.parse(req.url) catch |err| {
self.active -= 1;
self.handles.release(handle);
log.warn(.http, "invalid url", .{ .err = err, .url = req.url });
return;
};
const header_list = blk: {
errdefer self.handles.release(handle);
errdefer {
self.active -= 1;
self.handles.release(handle);
}
try conn.setMethod(req.method);
try conn.setURL(req.url);
@@ -275,7 +282,10 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
};
{
errdefer self.handles.release(handle);
errdefer {
self.active -= 1;
self.handles.release(handle);
}
const transfer = try self.transfer_pool.create();
transfer.* = .{
@@ -299,7 +309,6 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
}
}
self.active += 1;
return self.perform(0);
}