Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(renderer): avoid abort on streaming timeout

ldm05de601b7e785
diff --git a/moli-renderer-v8/src/runtime/owner.rs b/moli-renderer-v8/src/runtime/owner.rs
index d0eb864a0..61c93284c 100644
--- a/moli-renderer-v8/src/runtime/owner.rs
+++ b/moli-renderer-v8/src/runtime/owner.rs
@@ -4437,7 +4437,13 @@ impl RendererOwnerHandle {
// empty page entry.
remove_page_on_bound_owner_local_store(token);
entry.reject_pending_phase_one_navigation("Location navigation was cancelled.");
- self.restore_live_page_entry(token, entry);
+ // Re-enter directly through the residence boundary. The
+ // rejection above consumes and closes the entry's last
+ // active PageVm, so the normal live-entry helper cannot
+ // settle renderer output. The sticky retirement is
+ // observed first by the store-level restore, which tears
+ // down the checked-out entry without requiring a PageVm.
+ restore_entry_after_command_on_bound_owner_local_store(token, entry);
}
}
RenderRuntimeTurn::ContinueLivePageNavigationPostParseLifecycle { token, .. } => {
diff --git a/moli-test-support/src/routes_core.rs b/moli-test-support/src/routes_core.rs
index 0b70b60be..ce04e46b7 100644
--- a/moli-test-support/src/routes_core.rs
+++ b/moli-test-support/src/routes_core.rs
@@ -467,6 +467,37 @@ pub(super) async fn streaming_chunked_html_page() -> Response {
.expect("streaming html response should build")
}
+pub(super) async fn streaming_slow_html_tail_page() -> Response {
+ let (tx, rx) = tokio::sync::mpsc::channel(2);
+ tokio::spawn(async move {
+ if tx
+ .send(Ok::<Bytes, std::convert::Infallible>(Bytes::from_static(
+ b"<!doctype html><html><head><title>slow tail</title></head><body><main id=\"early\">early",
+ )))
+ .await
+ .is_err()
+ {
+ return;
+ }
+ // Keep initial page creation parked in its streaming-parser
+ // continuation long enough for a caller-owned readiness deadline to
+ // cancel the fetch and synchronously tear down the browser context.
+ sleep(Duration::from_millis(1_000)).await;
+ let _ = tx
+ .send(Ok::<Bytes, std::convert::Infallible>(Bytes::from_static(
+ b"</main></body></html>",
+ )))
+ .await;
+ });
+
+ Response::builder()
+ .header(CONTENT_TYPE, "text/html; charset=utf-8")
+ .body(Body::from_stream(
+ tokio_stream::wrappers::ReceiverStream::new(rx),
+ ))
+ .expect("slow-tail streaming html response should build")
+}
+
pub(super) async fn location_nav_replace_source_page() -> Html<&'static str> {
Html(LOCATION_NAV_REPLACE_SOURCE_HTML)
}
diff --git a/moli-test-support/src/server_routes.rs b/moli-test-support/src/server_routes.rs
index abd4bf973..8d0778d0d 100644
--- a/moli-test-support/src/server_routes.rs
+++ b/moli-test-support/src/server_routes.rs
@@ -95,6 +95,10 @@ pub(super) fn build_router() -> Router {
get(concurrent_shared_state_b_page),
)
.route("/streaming/chunked-html", get(streaming_chunked_html_page))
+ .route(
+ "/streaming/slow-html-tail",
+ get(streaming_slow_html_tail_page),
+ )
.route(
"/location-nav/replace-source",
get(location_nav_replace_source_page),
diff --git a/moli/tests/fetch_cli.rs b/moli/tests/fetch_cli.rs
index 38b82955a..1b40d8692 100644
--- a/moli/tests/fetch_cli.rs
+++ b/moli/tests/fetch_cli.rs
@@ -22,6 +22,7 @@ use serde_json::Value;
use std::{
io::Write,
path::PathBuf,
+ process::Command,
sync::{
Arc,
atomic::{AtomicUsize, Ordering},
@@ -2890,6 +2891,62 @@ fn cli_dump_json_keeps_transport_failures_as_process_errors() -> Result<()> {
Ok(())
}
+#[test]
+fn cli_streaming_page_creation_timeout_exits_cleanly_for_every_wait_mode() -> Result<()> {
+ let runtime = tokio::runtime::Runtime::new()?;
+ let server = runtime.block_on(FixtureServer::spawn())?;
+ let url = server.url("/streaming/slow-html-tail");
+
+ // Run a real child process so this regression distinguishes the expected
+ // exit code from SIGABRT. The response has committed its headers and first
+ // HTML chunk, but page creation remains parked on the delayed parser tail
+ // when the shared readiness deadline expires.
+ for wait_until in [
+ "domcontentloaded",
+ "load",
+ "networkidle",
+ "domstable",
+ "done",
+ ] {
+ let output = Command::new(env!("CARGO_BIN_EXE_moli"))
+ .args([
+ "fetch",
+ "--log-level",
+ "error",
+ "--http-no-proxy",
+ "*",
+ "--wait-until",
+ wait_until,
+ "--timeout",
+ "400",
+ "--dump",
+ "html",
+ &url,
+ ])
+ .output()?;
+ let stdout = clean_output(&output.stdout);
+ let stderr = clean_output(&output.stderr);
+
+ assert_eq!(
+ output.status.code(),
+ Some(1),
+ "wait_until={wait_until} must report a normal fetch failure instead of aborting: stdout={stdout}\nstderr={stderr}"
+ );
+ assert!(stdout.is_empty(), "wait_until={wait_until} stdout={stdout}");
+ assert!(
+ stderr.contains("timed out after 400 ms"),
+ "wait_until={wait_until} stderr={stderr}"
+ );
+ assert!(
+ !stderr.contains("resident renderer page entry must retain an active PageVm"),
+ "wait_until={wait_until} leaked the renderer teardown invariant: stderr={stderr}"
+ );
+ }
+
+ runtime.block_on(server.shutdown());
+ Ok(())
+}
+
#[test]
fn cli_domcontentloaded_exit_stays_stable_with_inflight_background_fetch_tail() -> Result<()> {
let runtime = tokio::runtime::Runtime::new()?;