fix(infra): Docker daemon 不可用时不再 panic
DOCKER_CLIENT 是 LazyLock<Docker>,socket 缺失时 .expect() 直接 panic; 而 release profile 是 panic="abort",会让整个服务进程挂掉——但博客本身并不依赖 Docker。 改为 LazyLock<Option<Docker>>:连接失败记 error 日志后存 None。 新增 get_docker() 在 None 时返回 IOError(NotFound),run_in_container / run_in_container_stream 通过 ? 向上冒泡,最终在 execute.rs 的错误脱敏层映射为 「系统暂时不可用」,其余功能不受影响。
This commit is contained in:
parent
65a7b1226f
commit
832b7c626d
@ -46,12 +46,14 @@ pub static DOCKER_CLIENT: LazyLock<Option<Docker>> = LazyLock::new(|| {
|
||||
/// `NotFound` 既不命中 `TimedOut` 也不命中超时判断,会走 execute.rs 的通用失败路径
|
||||
/// (`ExecStatus::Failed` + 「系统暂时不可用」),不会误报成超时。
|
||||
fn get_docker() -> Result<&'static Docker, bollard::errors::Error> {
|
||||
DOCKER_CLIENT.as_ref().ok_or_else(|| bollard::errors::Error::IOError {
|
||||
err: std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
"Docker daemon 不可用(未安装或未运行)",
|
||||
),
|
||||
})
|
||||
DOCKER_CLIENT
|
||||
.as_ref()
|
||||
.ok_or_else(|| bollard::errors::Error::IOError {
|
||||
err: std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
"Docker daemon 不可用(未安装或未运行)",
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_host_config(limits: &ResourceLimits) -> HostConfig {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user