Skip to content

SMOODEV-2498: add bounded connect timeout to smooai-fetch#88

Open
brentrager wants to merge 1 commit into
mainfrom
SMOODEV-2498-connect-timeout
Open

SMOODEV-2498: add bounded connect timeout to smooai-fetch#88
brentrager wants to merge 1 commit into
mainfrom
SMOODEV-2498-connect-timeout

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

api-prime's ~16s API stalls (SMOODEV-2481) traced to fresh SYNs black-holing to dead pod IPs still lingering in a ClusterIP's iptables during an endpoint-removal race. smooai-fetch builds a fresh reqwest::Client per request/retry (so there is no stale keepalive to fix) but set no connect timeout — so reqwest waited the full whole-request timeout (15s in api-prime) before the existing retry could land on a live pod.

Fix

Add a bounded connect timeout so a black-holed connect fails in ~the configured window and the existing retry lands on a live endpoint, while slow-but-alive handlers (governed by the whole-request timeout) are untouched.

  • FetchBuilder::with_connect_timeout(ms) — mirrors with_timeout.
  • FetchOptions.connect_timeout_ms: Option<u64>default None, so existing consumers are behaviorally unchanged.
  • do_single_request builds via reqwest::Client::builder().connect_timeout(Duration::from_millis(ms)).build()? when set; falls back to the identical reqwest::Client::new() path when unset.

Test

tests/connect_timeout_tests.rs: a connect to a non-routable/black-hole IP (10.255.255.1:80) with a 500ms connect timeout and a 5s whole-request timeout returns a FetchError::Request in ~0.5s (asserted < 3s) instead of hanging to the whole timeout. Full suite green (cargo test -p smooai-fetch --locked: 111 passed), fmt + clippy clean.

🤖 Generated with Claude Code

api-prime's ~16s API stalls (SMOODEV-2481) were fresh SYNs black-holing to
dead pod IPs still lingering in a ClusterIP's iptables (endpoint-removal
race). smooai-fetch builds a fresh reqwest::Client per request/retry but set
no connect timeout, so reqwest waited the full whole-request timeout (15s)
before the retry could land on a live pod.

Add FetchBuilder::with_connect_timeout(ms) (and FetchOptions.connect_timeout_ms,
default None so existing consumers are unchanged). When set, do_single_request
builds the client via reqwest::Client::builder().connect_timeout(...); when
unset the path is behaviorally identical (reqwest::Client::new()). A bounded
connect timeout fails a black-holed connect in ~the configured window while
slow-but-alive handlers (whole-request timeout) are untouched.

Covered by tests/connect_timeout_tests.rs: a connect to a non-routable IP
returns a request error in ~the connect window (~0.5s) rather than hanging to
the whole-request timeout.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1e1d486

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant