diff options
| author | dev <dev@localhost> | 2026-10-21 18:37:27 +0000 |
|---|---|---|
| committer | dev <dev@localhost> | 2026-10-21 18:37:27 +0000 |
| commit | 9d40159cad3b55c753ed02e7a4dee8cc7b6d15eb (patch) | |
| tree | 05572dd06f27e5817272f80e04bb7609f19b3f61 /src/client/stream.rs | |
| parent | 3705a6141c42a828e714853d089c48e88a232de5 (diff) | |
| download | aichat-9d40159cad3b55c753ed02e7a4dee8cc7b6d15eb.tar.gz | |
Add request timeout and retry support to aichat HTTP clients
- Add timeout, retries, retry_delay_ms, and retry_max_delay_ms options to
client extra config to bound long-running requests and retry failed
attempts with exponential backoff.
- Apply a total request timeout via reqwest .timeout().
- Implement retry with exponential backoff for non-streaming and streaming
chat completions.
- Disable reqwest-eventsource internal auto-reconnect so it does not loop
forever; outer retry logic is now the single owner of retry behavior.
- Document the new options in config.example.yaml.
Diffstat (limited to 'src/client/stream.rs')
| -rw-r--r-- | src/client/stream.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/client/stream.rs b/src/client/stream.rs index fd82c94..94802a8 100644 --- a/src/client/stream.rs +++ b/src/client/stream.rs @@ -4,6 +4,7 @@ use crate::utils::AbortSignal; use anyhow::{anyhow, bail, Context, Result}; use futures_util::{Stream, StreamExt}; use reqwest::RequestBuilder; +use reqwest_eventsource::retry::Never; use reqwest_eventsource::{Error as EventSourceError, Event, RequestBuilderExt}; use serde_json::Value; use tokio::sync::mpsc::UnboundedSender; @@ -95,6 +96,11 @@ where F: FnMut(SseMmessage) -> Result<bool>, { let mut es = builder.eventsource()?; + // Disable the eventsource client's automatic reconnect so the outer retry + // logic (driven by ExtraConfig.retries) is the single owner of retry + // behavior. Without this, a dropped connection is re-opened internally in a + // loop that never surfaces the failure to the caller. + es.set_retry_policy(Box::new(Never)); while let Some(event) = es.next().await { match event { Ok(Event::Open) => {} |
