Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| `ASTRBOT_BACKEND_READY_HTTP_PATH` | 就绪探针 HTTP 路径 | 默认 `/api/stat/start-time` |
| `ASTRBOT_BACKEND_READY_PROBE_TIMEOUT_MS` | 就绪探针单次超时 | 默认回退到 `ASTRBOT_BACKEND_PING_TIMEOUT_MS` |
| `ASTRBOT_BACKEND_READY_POLL_INTERVAL_MS` | 就绪轮询间隔 | 默认 `300`,并按边界 clamp |
| `ASTRBOT_BACKEND_PING_TIMEOUT_MS` | 后端 ping 超时 | 默认 `800`,范围 `50~30000` |
| `ASTRBOT_BACKEND_PING_TIMEOUT_MS` | 后端 ping 超时 | 默认 `5000`,范围 `50~30000` |
| `ASTRBOT_BRIDGE_BACKEND_PING_TIMEOUT_MS` | 桥接层 ping 超时 | 默认回退到 `ASTRBOT_BACKEND_PING_TIMEOUT_MS` |
| `ASTRBOT_BACKEND_CMD` | 后端启动命令覆盖 | 未设置则按 launch plan 推导 |
| `ASTRBOT_BACKEND_CWD` | 后端工作目录覆盖 | 未设置则按 launch plan 推导 |
Expand Down
10 changes: 9 additions & 1 deletion src-tauri/src/app_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) const BACKEND_STARTUP_HEARTBEAT_PATH_ENV: &str =
"ASTRBOT_BACKEND_STARTUP_HEARTBEAT_PATH";
pub(crate) const DEFAULT_BACKEND_STARTUP_HEARTBEAT_RELATIVE_PATH: &str =
"data/backend-startup-heartbeat.json";
pub(crate) const DEFAULT_BACKEND_PING_TIMEOUT_MS: u64 = 800;
pub(crate) const DEFAULT_BACKEND_PING_TIMEOUT_MS: u64 = 5_000;
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
pub(crate) const BACKEND_PING_TIMEOUT_MIN_MS: u64 = 50;
pub(crate) const BACKEND_PING_TIMEOUT_MAX_MS: u64 = 30_000;
pub(crate) const BACKEND_PING_TIMEOUT_ENV: &str = "ASTRBOT_BACKEND_PING_TIMEOUT_MS";
Expand All @@ -55,3 +55,11 @@ pub(crate) const STARTUP_MODE_ENV: &str = "ASTRBOT_DESKTOP_STARTUP_MODE";
pub(crate) const CREATE_NO_WINDOW: u32 = 0x0800_0000;
#[cfg(target_os = "windows")]
pub(crate) const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200;

#[cfg(test)]
mod tests {
#[test]
fn default_backend_ping_timeout_is_five_seconds() {
assert_eq!(super::DEFAULT_BACKEND_PING_TIMEOUT_MS, 5_000);
}
}
16 changes: 12 additions & 4 deletions src-tauri/src/backend/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,22 @@ impl BackendState {
};
let port = parsed.port_or_known_default().unwrap_or(80);
let timeout = Duration::from_millis(timeout_ms.max(50));
let started_at = Instant::now();

let addrs = match (host.as_str(), port).to_socket_addrs() {
Ok(addrs) => addrs.collect::<Vec<_>>(),
Ok(addrs) => addrs,
Err(_) => return false,
};
addrs
.iter()
.any(|address| TcpStream::connect_timeout(address, timeout).is_ok())
for address in addrs {
let remaining = timeout.saturating_sub(started_at.elapsed());
if remaining.is_zero() {
return false;
}
if TcpStream::connect_timeout(&address, remaining).is_ok() {
return true;
}
}
false
}

pub(crate) fn request_backend_response_bytes(
Expand Down