Skip to content

Commit 19c9080

Browse files
committed
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 (#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.
1 parent 05192b6 commit 19c9080

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/http/Client.zig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,14 @@ pub fn tick(self: *Client, timeout_ms: usize) !void {
185185

186186
pub fn request(self: *Client, req: Request) !void {
187187
if (self.handles.getFreeHandle()) |handle| {
188+
self.active += 1;
188189
return self.makeRequest(handle, req);
189190
}
190191

191192
const node = try self.queue_node_pool.create();
192193
node.data = req;
193194
self.queue.append(node);
195+
self.active += 1;
194196
}
195197

196198
// See ScriptManager.blockingGet
@@ -234,13 +236,18 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
234236

235237
// we need this for cookies
236238
const uri = std.Uri.parse(req.url) catch |err| {
239+
self.active -= 1;
237240
self.handles.release(handle);
238241
log.warn(.http, "invalid url", .{ .err = err, .url = req.url });
239242
return;
240243
};
241244

242245
const header_list = blk: {
243-
errdefer self.handles.release(handle);
246+
errdefer {
247+
self.active -= 1;
248+
self.handles.release(handle);
249+
}
250+
244251
try conn.setMethod(req.method);
245252
try conn.setURL(req.url);
246253

@@ -275,7 +282,10 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
275282
};
276283

277284
{
278-
errdefer self.handles.release(handle);
285+
errdefer {
286+
self.active -= 1;
287+
self.handles.release(handle);
288+
}
279289

280290
const transfer = try self.transfer_pool.create();
281291
transfer.* = .{
@@ -299,7 +309,6 @@ fn makeRequest(self: *Client, handle: *Handle, req: Request) !void {
299309
}
300310
}
301311

302-
self.active += 1;
303312
return self.perform(0);
304313
}
305314

0 commit comments

Comments
 (0)