Skip to content

fix: set a default timeout for REST requests#1025

Merged
EhabY merged 2 commits into
mainfrom
fix/default-request-timeout
Jul 8, 2026
Merged

fix: set a default timeout for REST requests#1025
EhabY merged 2 commits into
mainfrom
fix/default-request-timeout

Conversation

@EhabY

@EhabY EhabY commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #1024

Requests through the CoderApi axios instance had no timeout, so a request hung on a half-open TCP connection (network drop, system sleep) never settled — silently killing every poller that only reschedules after the previous request settles (announcements refresh, workspaces tree poll, OAuth token refresh).

Changes

  • defaults.timeout = 60_000 on the shared axios instance in CoderApi.create.
  • Unit tests for the default and per-request overrides.

Why no stream exemptions

The issue proposed { timeout: 0 } opt-outs for streaming calls, but they aren't needed: in axios's Node adapter, responseType: "stream" requests are marked done once response headers arrive, so the timeout only bounds the connect/header phase and never aborts an in-flight stream body. SSE streams and CLI downloads just get a bounded connect phase, which is desirable. Build endpoints return as soon as the build is queued, so nothing REST-side legitimately exceeds 60s.

Timeouts surface as regular axios network errors, handled by existing errToStr/retry paths.

Decision log
  • No standard to inherit: coder/coder site sets no axios timeout, and Go codersdk uses a bare http.Client{} bounded by per-request contexts.
  • 60s over 30s for headroom on slow deployments while still recovering pollers within a minute.
  • TCP keepalive on HTTP agents (faster dead-socket detection) deferred as a follow-up.
  • A coder.requestTimeout setting rejected as premature configurability.

🤖 Generated by Coder Agents on behalf of @EhabY

Requests through the CoderApi axios instance had no timeout, so a
request hung on a half-open TCP connection (network drop, system
sleep) never settled. This silently killed every poller that only
reschedules after the previous request settles: announcements
refresh, the workspaces tree poll, and the OAuth background token
refresh.

Set a 60s default on the shared instance. Streaming responses (SSE,
CLI binary download) are unaffected past the header phase: axios only
enforces the timeout until response headers arrive and never aborts
an in-flight stream body.

Closes #1024
@EhabY EhabY self-assigned this Jul 7, 2026
@EhabY EhabY force-pushed the fix/default-request-timeout branch from 90a16eb to 74fcdcd Compare July 8, 2026 11:49
@EhabY EhabY merged commit 676b4e2 into main Jul 8, 2026
12 of 13 checks passed
@EhabY EhabY deleted the fix/default-request-timeout branch July 8, 2026 11:50
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.

Set a default timeout for REST requests

2 participants