Remove potential processing blocking with CDP

When using CDP, we poll the HTTP clients along with the CDP socket. Because this
polling can be long, we first process any pending message. This can end up
processing _all_ messages, in which case the poll will block for a long time.

This change makes it so that when the initial processing processes 1+ message,
we do not poll, but rather return. This allows the page lifecycle to be
processed normally (and not just blocking on poll, waiting for the CDP client
to send data).
This commit is contained in:
Karl Seguin
2025-10-09 13:18:47 +08:00
parent 2d6e2551f6
commit 76e8506022
2 changed files with 9 additions and 4 deletions

View File

@@ -106,7 +106,7 @@ pub fn LogInterceptor(comptime BC: type) type {
}, .{
.session_id = self.bc.session_id,
}) catch |err| {
log.err(.interceptor, "failed to send", .{.err = err});
log.err(.interceptor, "failed to send", .{ .err = err });
};
}
};

View File

@@ -393,7 +393,9 @@ fn perform(self: *Client, timeout_ms: c_int) !PerformStatus {
// We're potentially going to block for a while until we get data. Process
// whatever messages we have waiting ahead of time.
try self.processMessages();
if (try self.processMessages()) {
return .normal;
}
var status = PerformStatus.normal;
if (self.extra_socket) |s| {
@@ -411,12 +413,13 @@ fn perform(self: *Client, timeout_ms: c_int) !PerformStatus {
try errorMCheck(c.curl_multi_poll(multi, null, 0, timeout_ms, null));
}
try self.processMessages();
_ = try self.processMessages();
return status;
}
fn processMessages(self: *Client) !void {
fn processMessages(self: *Client) !bool {
const multi = self.multi;
var processed = false;
var messages_count: c_int = 0;
while (c.curl_multi_info_read(multi, &messages_count)) |msg_| {
const msg: *c.CURLMsg = @ptrCast(msg_);
@@ -475,10 +478,12 @@ fn processMessages(self: *Client) !void {
.transfer = transfer,
});
}
processed = true;
} else |err| {
self.requestFailed(transfer, err);
}
}
return processed;
}
fn endTransfer(self: *Client, transfer: *Transfer) void {