From 529b8acfbe3973b2dda21fb96df3e10ef71c0a60 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sat, 14 Mar 2026 14:42:26 -0500 Subject: [PATCH] fix: retry Chrome launch up to 3 times on transient startup failures (#791) Chrome occasionally crashes during startup on CI runners before printing the DevTools URL, causing random e2e test failures across different tests each run. Retry the launch with a 500ms delay to handle these transient crashes. --- cli/src/native/cdp/chrome.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cli/src/native/cdp/chrome.rs b/cli/src/native/cdp/chrome.rs index 3130a13..81d9926 100644 --- a/cli/src/native/cdp/chrome.rs +++ b/cli/src/native/cdp/chrome.rs @@ -194,6 +194,29 @@ pub fn launch_chrome(options: &LaunchOptions) -> Result { } }; + let max_attempts = 3; + let mut last_err = String::new(); + + for attempt in 1..=max_attempts { + match try_launch_chrome(&chrome_path, options) { + Ok(process) => return Ok(process), + Err(e) => { + last_err = e; + if attempt < max_attempts { + eprintln!( + "[chrome] Launch attempt {}/{} failed, retrying in 500ms...", + attempt, max_attempts + ); + std::thread::sleep(Duration::from_millis(500)); + } + } + } + } + + Err(last_err) +} + +fn try_launch_chrome(chrome_path: &Path, options: &LaunchOptions) -> Result { let ChromeArgs { args, temp_user_data_dir, @@ -205,7 +228,7 @@ pub fn launch_chrome(options: &LaunchOptions) -> Result { } }; - let mut child = Command::new(&chrome_path) + let mut child = Command::new(chrome_path) .args(&args) .stdin(Stdio::null()) .stdout(Stdio::null())