mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 09:35:59 -04:00
when work is done, don't keep polling, return to process it
This commit is contained in:
@@ -80,18 +80,6 @@ pub fn shutdown(self: *Server) void {
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all in-flight workers to drain. Useful for tests that
|
||||
// mutate process-global state (e.g. log filters) and need to ensure
|
||||
// no worker thread is reading that state before mutating it.
|
||||
pub fn waitIdle(self: *Server) void {
|
||||
if (@import("builtin").is_test == false) {
|
||||
@compileError("waitIdle is only meant to be called in tests");
|
||||
}
|
||||
while (self.active_threads.load(.monotonic) > 0) {
|
||||
std.Thread.sleep(1 * std.time.ns_per_ms);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Server) void {
|
||||
self.shutdown();
|
||||
|
||||
@@ -405,9 +393,6 @@ test "Client: http valid handshake" {
|
||||
}
|
||||
|
||||
test "Client: read invalid websocket message" {
|
||||
const filter: testing.LogFilter = .init(&.{.cdp});
|
||||
defer filter.deinit();
|
||||
|
||||
// 131 = 128 (fin) | 3 where 3 isn't a valid type
|
||||
try assertWebSocketError(
|
||||
1002,
|
||||
|
||||
@@ -667,9 +667,14 @@ fn perform(self: *Client, timeout_ms: c_int) anyerror!void {
|
||||
try self.trackConn(conn);
|
||||
}
|
||||
|
||||
// Process completions queued from the curl_multi_perform above before
|
||||
// we potentially block.
|
||||
_ = try self.processMessages();
|
||||
// We just processed completions; their done_callbacks may have
|
||||
// scheduled microtasks (JS continuations) or queued new transfers.
|
||||
// Return without polling so the caller (_tick) can run macrotasks
|
||||
// and re-evaluate. Otherwise we'd sleep on cdp_link_active for up
|
||||
// to timeout_ms while pending JS work sits idle.
|
||||
if (try self.processMessages()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Poll for HTTP I/O. The Network thread will call curl_multi_wakeup
|
||||
// on our multi handle whenever it pushes to our inbox, so we drop
|
||||
|
||||
@@ -218,10 +218,8 @@ pub fn onDisconnect(self: *CDP, err: ?anyerror) void {
|
||||
if (WS.errorReply(e)) |close_frame| {
|
||||
self.conn.send(close_frame) catch {};
|
||||
}
|
||||
log.warn(.cdp, "CDP disconnect", .{ .err = e });
|
||||
} else {
|
||||
log.info(.cdp, "CDP disconnect", .{});
|
||||
}
|
||||
log.info(.cdp, "CDP disconnect", .{ .err = err });
|
||||
}
|
||||
|
||||
pub fn sendJSON(self: *CDP, message: anytype) !void {
|
||||
|
||||
@@ -657,7 +657,7 @@ fn processCdpEvents(self: *Network) void {
|
||||
// know it should exit. Drop with notify=true so
|
||||
// on_disconnect surfaces a .disconnect into the inbox.
|
||||
// dropCdp wakes the worker.
|
||||
lp.log.warn(.cdp, "CDP onData", .{ .err = err });
|
||||
lp.log.info(.cdp, "CDP onData", .{ .err = err });
|
||||
self.dropCdp(link, err, true);
|
||||
any_removed = true;
|
||||
continue;
|
||||
|
||||
@@ -761,13 +761,6 @@ pub const LogFilter = struct {
|
||||
|
||||
/// Restores the log filters to their previous state.
|
||||
pub fn deinit(self: LogFilter) void {
|
||||
// Worker threads read log.opts.filter_scopes inside log.enabled,
|
||||
// so we must wait for any in-flight workers to drain before
|
||||
// writing it — otherwise we race the worker's load on its
|
||||
// teardown log line.
|
||||
if (test_cdp_server) |server| {
|
||||
server.waitIdle();
|
||||
}
|
||||
log.opts.filter_scopes = self.old_filter;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user