From db750e4fc5ce5de650a6d8fbbb8d77284d64adc0 Mon Sep 17 00:00:00 2001 From: Taylor Eernisse Date: Thu, 5 Feb 2026 11:21:40 -0500 Subject: [PATCH] fix: Graceful HTTP client fallbacks and overflow protection HTTP client initialization (embedding/ollama.rs, gitlab/client.rs): - Replace expect/panic with unwrap_or_else fallback to default Client - Log warning when configured client fails to build - Prevents crash on TLS/system configuration issues Doctor command (cli/commands/doctor.rs): - Handle reqwest Client::builder() failure in Ollama health check - Return Warning status with descriptive message instead of panicking - Ensures doctor command remains operational even with HTTP issues These changes improve resilience when running in unusual environments (containers with limited TLS, restrictive network policies, etc.) without affecting normal operation. Co-Authored-By: Claude Opus 4.5 --- src/cli/commands/doctor.rs | 16 ++++++++++++++-- src/embedding/ollama.rs | 9 ++++++++- src/gitlab/client.rs | 10 ++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/doctor.rs b/src/cli/commands/doctor.rs index a356a67..3b8741e 100644 --- a/src/cli/commands/doctor.rs +++ b/src/cli/commands/doctor.rs @@ -383,10 +383,22 @@ async fn check_ollama(config: Option<&Config>) -> OllamaCheck { let base_url = &config.embedding.base_url; let model = &config.embedding.model; - let client = reqwest::Client::builder() + let client = match reqwest::Client::builder() .timeout(std::time::Duration::from_secs(2)) .build() - .unwrap(); + { + Ok(client) => client, + Err(e) => { + return OllamaCheck { + result: CheckResult { + status: CheckStatus::Warning, + message: Some(format!("Failed to build HTTP client: {e}")), + }, + url: Some(base_url.clone()), + model: Some(model.clone()), + }; + } + }; match client.get(format!("{base_url}/api/tags")).send().await { Ok(response) if response.status().is_success() => { diff --git a/src/embedding/ollama.rs b/src/embedding/ollama.rs index 7076626..2e2c519 100644 --- a/src/embedding/ollama.rs +++ b/src/embedding/ollama.rs @@ -1,6 +1,7 @@ use reqwest::Client; use serde::{Deserialize, Serialize}; use std::time::Duration; +use tracing::warn; use crate::core::error::{LoreError, Result}; @@ -53,7 +54,13 @@ impl OllamaClient { let client = Client::builder() .timeout(Duration::from_secs(config.timeout_secs)) .build() - .expect("Failed to create HTTP client"); + .unwrap_or_else(|e| { + warn!( + error = %e, + "Failed to build configured Ollama HTTP client; falling back to default client" + ); + Client::new() + }); Self { client, config } } diff --git a/src/gitlab/client.rs b/src/gitlab/client.rs index f400015..1251e8d 100644 --- a/src/gitlab/client.rs +++ b/src/gitlab/client.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use tokio::sync::Mutex; use tokio::time::sleep; -use tracing::debug; +use tracing::{debug, warn}; use super::types::{ GitLabDiscussion, GitLabIssue, GitLabIssueRef, GitLabLabelEvent, GitLabMergeRequest, @@ -73,7 +73,13 @@ impl GitLabClient { .default_headers(headers) .timeout(Duration::from_secs(30)) .build() - .expect("Failed to create HTTP client"); + .unwrap_or_else(|e| { + warn!( + error = %e, + "Failed to build configured HTTP client; falling back to default client" + ); + Client::new() + }); Self { client,