From 0fdd7a4930d5abe17295fe1eb133a91a8501e04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 4 Nov 2026 12:04:29 +0100 Subject: [PATCH] fix: give pg0 info's health check more time and show psql's error The connect timeout was 1s (2s after libpq rounding), too short on some Windows machines, so live instances were reported as stopped. Raise it to 10s and statement_timeout to 5s, and print psql's stderr when the check fails. Fixes #41. --- src/main.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 617f36d..02cbbe3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1374,7 +1374,7 @@ fn is_database_healthy(info: &InstanceInfo) -> bool { return false; } - process::Command::new(psql_path) + let output = process::Command::new(psql_path) // Avoid user psql configuration and fail instead of prompting if the // saved instance credentials no longer work. .args(["-X", "-w", "-q", "-v", "ON_ERROR_STOP=1"]) @@ -1382,13 +1382,29 @@ fn is_database_healthy(info: &InstanceInfo) -> bool { .args(["-U", &info.username, "-d", &info.database]) .args(["-c", "SELECT 1"]) // Keep health checks bounded when a broken backend accepts a TCP - // connection but never completes startup or the query. - .env("PGCONNECT_TIMEOUT", "1") - .env("PGOPTIONS", "-c statement_timeout=1000") + // connection but never completes startup or the query. Generous + // enough for Windows, where each connection starts a new backend + // process and antivirus scanning can take seconds (#41). + .env("PGCONNECT_TIMEOUT", "10") + .env("PGOPTIONS", "-c statement_timeout=5000") .env("PGPASSWORD", &info.password) - .output() - .map(|output| output.status.success()) - .unwrap_or(false) + .output(); + match output { + Ok(output) if output.status.success() => true, + Ok(output) => { + // stderr only: stdout may be JSON that callers parse. + eprintln!( + "Warning: PostgreSQL on port {} is running but did not answer a test query: {}", + info.port, + String::from_utf8_lossy(&output.stderr).trim() + ); + false + } + Err(e) => { + eprintln!("Warning: could not run psql to check PostgreSQL on port {}: {}", info.port, e); + false + } + } } fn psql(name: String, args: Vec) -> Result<(), CliError> {