Allow slow daemon startup while detecting early process exits (#57253)

## Why

On Linux, a cold start from a rotational disk can exceed the ten-second readiness timeout. Extending that timeout should still let startup failures surface promptly when the daemon exits.

## What changed

- Increase the Linux readiness timeout to 30 seconds, matching macOS.
- Stop waiting for readiness when the published daemon process exits, preserving the PID reservation and reporting startup diagnostics, including stderr.
- Kill pending `ps` subprocesses when their process checks are dropped.

## Testing

Add coverage for a managed daemon becoming ready after 15 seconds and for reporting an exited daemon's stderr within five seconds.

GitOrigin-RevId: c663e52bea9039807f14ef8fc4b44aca9df3df21
This commit is contained in:
Eric Traut
2026-10-26 21:05:47 +00:00
committed by copyberry
parent f358635d8e
commit 987b8dfc0f
4 changed files with 72 additions and 13 deletions
@@ -10,6 +10,7 @@ use std::path::PathBuf;
use serde::Serialize;
pub(crate) use pid::PidBackend;
pub(crate) use pid::wait_for_process_exit;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
@@ -460,6 +460,20 @@ impl PidBackend {
}
}
/// Wait for a published process to exit without modifying its PID reservation.
pub(crate) async fn wait_for_process_exit(pid_file: &Path) {
loop {
// A missing or empty record can belong to a launch still publishing its PID.
if let Ok(contents) = fs::read(pid_file).await
&& let Ok(record) = serde_json::from_slice::<PidRecord>(&contents)
&& matches!(process_matches_record(&record).await, Ok(false))
{
return;
}
sleep(crate::START_POLL_INTERVAL).await;
}
}
pub(crate) async fn read_stderr_log_tail(pid_file: &Path) -> Result<Option<PidLogTail>> {
let path = stderr_log_file_for_pid_file(pid_file);
let Some(contents) = read_log_tail(&path, STDERR_LOG_TAIL_BYTES).await? else {
@@ -757,6 +771,7 @@ async fn read_process_start_time(pid: u32) -> Result<String> {
async fn read_process_details(pid: u32) -> Result<(String, String)> {
let output = Command::new("ps")
.args(["-p", &pid.to_string(), "-o", "stat=", "-o", "lstart="])
.kill_on_drop(true)
.output()
.await
.context("failed to invoke ps for pid-managed app server")?;