mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Fix CDP WebSocket connection dying during complex page navigation
The CDP timeout handler in httpLoop had two compounding bugs: 1. Unit mismatch: timestamp(.monotonic) returns seconds, but ms_remaining is in milliseconds. The comparison and subtraction mixed units. 2. Double-counting: In the .done branch, elapsed was computed as absolute time since last_message, but last_message was never updated in this branch. Each iteration subtracted the growing total elapsed seconds from an already-decremented ms_remaining. During complex page loads, Session._wait() returns .done rapidly (due to JS macrotask execution, background tasks, or errors). Each rapid .done return subtracted the growing elapsed (seconds) from ms_remaining (milliseconds), draining it to zero in ~2 seconds instead of the configured 10-second timeout. Fix: use milliTimestamp() for consistent units, update last_message in the .done branch for incremental elapsed tracking, and use >= for correct boundary comparison. Fixes #1849 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -295,7 +295,7 @@ pub const Client = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cdp = &self.mode.cdp;
|
var cdp = &self.mode.cdp;
|
||||||
var last_message = timestamp(.monotonic);
|
var last_message = milliTimestamp(.monotonic);
|
||||||
var ms_remaining = self.ws.timeout_ms;
|
var ms_remaining = self.ws.timeout_ms;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -304,7 +304,7 @@ pub const Client = struct {
|
|||||||
if (self.readSocket() == false) {
|
if (self.readSocket() == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
last_message = timestamp(.monotonic);
|
last_message = milliTimestamp(.monotonic);
|
||||||
ms_remaining = self.ws.timeout_ms;
|
ms_remaining = self.ws.timeout_ms;
|
||||||
},
|
},
|
||||||
.no_page => {
|
.no_page => {
|
||||||
@@ -319,16 +319,18 @@ pub const Client = struct {
|
|||||||
if (self.readSocket() == false) {
|
if (self.readSocket() == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
last_message = timestamp(.monotonic);
|
last_message = milliTimestamp(.monotonic);
|
||||||
ms_remaining = self.ws.timeout_ms;
|
ms_remaining = self.ws.timeout_ms;
|
||||||
},
|
},
|
||||||
.done => {
|
.done => {
|
||||||
const elapsed = timestamp(.monotonic) - last_message;
|
const now = milliTimestamp(.monotonic);
|
||||||
if (elapsed > ms_remaining) {
|
const elapsed = now - last_message;
|
||||||
|
if (elapsed >= ms_remaining) {
|
||||||
log.info(.app, "CDP timeout", .{});
|
log.info(.app, "CDP timeout", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ms_remaining -= @intCast(elapsed);
|
ms_remaining -= @intCast(elapsed);
|
||||||
|
last_message = now;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -501,6 +503,7 @@ fn buildJSONVersionResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const timestamp = @import("datetime.zig").timestamp;
|
pub const timestamp = @import("datetime.zig").timestamp;
|
||||||
|
pub const milliTimestamp = @import("datetime.zig").milliTimestamp;
|
||||||
|
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
test "server: buildJSONVersionResponse" {
|
test "server: buildJSONVersionResponse" {
|
||||||
|
|||||||
Reference in New Issue
Block a user