#1692·9router

Hardcoded timeouts (connect 20s, stall 30s) cause 85%+ errors — 5 open PRs, 4 issues, no fix merged yet

Author: Xpos587Created Jun 5, 2026Updated Sep 30, 2026

Problem

When using 9router with ollama providers, 87% of all errors are timeout-related. Two hardcoded timeout values are too aggressive:

Root Cause (confirmed from source code)

In src/open-sse/config/runtimeConfig.js:

javascript
// Stream stall: kill stream if no tokens received in 30s
export const STREAM_STALL_TIMEOUT_MS = 30 * 1000;

// Connect timeout: abort if upstream doesn't return response headers in 20s
export const FETCH_CONNECT_TIMEOUT_MS = 20 * 1000;

// Retry config (also hardcoded)
export const DEFAULT_RETRY_CONFIG = {
  429: { attempts: 0, delayMs: 0 },
  502: { attempts: 3, delayMs: 3000 },
  503: { attempts: 3, delayMs: 2000 },
};

Both STREAM_STALL_TIMEOUT_MS and FETCH_CONNECT_TIMEOUT_MS are hardcoded — not configurable via settings DB, environment variables, or dashboard UI.

Evidence (production, last 10k log lines)

Error type Count % of errors
502 fetch connect timeout 902 85%
403 subscription required 108 10%
stream stall timeout (non-502) 44 4%
400 context too long 24 2%
404 model not found 6 1%

Per-model timeout rates:

Model Requests Connect timeouts Fail rate
ollama/glm-5.1 558 79 14%
ollama/kimi-k2.6 42 8 19%
ollama/qwen3-coder-next 67 4 6%
ollama/minimax-m3 12 2 17%

Stream stall timeout details

44 occurrences with durations:

  • Min: 33s, Median: ~36s, Max: 196s, Avg: 56s

This happens because reasoning models (GLM-5.1, deepseek) think for 30-60s before emitting the first token. The 30s stallTimeout kills these legitimate long-inference requests.

When providers respond normally

Direct testing shows ollama providers respond in 0.5-2.6s when not timing out:

ollama/glm-5.1:           1.1-2.6s (200 OK)
ollama/kimi-k2.6:         1.2-2.6s (200 OK)
ollama/deepseek-v4-pro:   0.8-1.2s (200 OK)
ollama/deepseek-v4-flash: 1.2-1.4s (200 OK)
ollama/qwen3-coder-next:  0.6-1.3s (200 OK)

The timeouts are intermittent — providers work most of the time but occasionally take 20-60s to connect or start streaming.

Retry math

With connectTimeout=20s × 3 retries = 60s wasted before returning 502 to client.

Suggested fix

  1. Make FETCH_CONNECT_TIMEOUT_MS and STREAM_STALL_TIMEOUT_MS configurable via:
    • Settings DB (dashboard UI)
    • Environment variables: FETCH_CONNECT_TIMEOUT_MS, STREAM_STALL_TIMEOUT_MS
    • Per-provider timeout overrides
  2. Increase defaults:
    • FETCH_CONNECT_TIMEOUT_MS: 20000 → 60000 (accommodate slow upstream connections)
    • STREAM_STALL_TIMEOUT_MS: 30000 → 120000 (accommodate reasoning models that think before streaming)
  3. For reasoning models, consider detecting reasoning_content in stream and using a separate REASONING_STALL_TIMEOUT_MS

Environment

  • 9router v0.4.66 (Docker decolua/9router:latest)
  • 4 ollama provider connections (paid accounts)
  • Hetzner dedicated server (Debian, Docker)
  • Combo models: glm-5.1, kimi-k2.6 (single-provider each, no fallback)

Workaround

No workaround available. The gateway_timeout_seconds setting mentioned in #1659 does not exist in the current codebase or settings schema.