[Security Audit] Caddy timeout at exact backend limit causes intermittent 504 errors #4
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: MEDIUM
Description
The Caddy reverse proxy read_timeout/write_timeout (30s) equals the backend's maximum fetch time (15s timeout x 2 retries = 30s), creating a race condition that causes intermittent 504 Gateway Timeout errors for slow requests.
Affected File
Details
When a request takes exactly 30s, the race between Caddy timeout and backend completion causes 504 errors. Per the project's own documented best practice, Caddy timeouts must be strictly greater than the backend's maximum.
Impact
Users experience intermittent 504 errors on slow pages (large works, search results), degrading availability and reliability.
Fix
Increase Caddy read_timeout and write_timeout to 60s in the Caddyfile to provide headroom above the 30s maximum backend time.
Auto-Triage Report for Issue #4
Status: Open
Existing Labels: bug (correct)
Assignee: @akiba (newly assigned)
Summary: [Security Audit] Caddy timeout at exact backend limit causes intermittent 504 errors. Severity: MEDIUM.
Assessment: Valid bug. Caddy read_timeout/write_timeout (30s) exactly equals the backend's max fetch time (15s timeout x 2 retries = 30s), creating a race condition. The documented best practice is that Caddy timeouts must be strictly greater than the backend's maximum.
Next Steps:
Triage Summary
Status: 🟡 Confirmed — Race condition causing intermittent 504 errors
Severity: MEDIUM
Priority: 🟠 High — affects user-facing reliability
Assessment
This is a legitimate race condition. Caddy's
read_timeoutandwrite_timeoutare both set to 30s, which equals the backend's maximum fetch time (15s timeout × 2 retries = 30s). When a request takes exactly 30s, Caddy and the backend race — if Caddy wins, the user gets a 504 even though the backend completed successfully.Recommended Next Steps
read_timeoutandwrite_timeoutto 60s in the Caddyfile (lines 39-40)Triage Actions Taken
bug(already set) ✅🤖 Triage Summary
Classification: Bug (MEDIUM severity)
Labels: bug ✅
Assignee: akiba ✅
Assessment: Real configuration bug — Caddy's read/write timeouts (30s) exactly equal the backend's maximum fetch time (15s × 2 retries = 30s), creating a race condition that causes intermittent 504 Gateway Timeout errors.
Recommended Next Steps:
Note: Per the project's own best practice, Caddy timeouts must be strictly greater than the backend's maximum to avoid this race condition.
🔄 Follow-up Triage (2026-06-30)
Status: Still open. Labels (
bug) and assignee (akiba) remain correct.Action needed: Increase Caddy
read_timeout/write_timeoutfrom 30s → 60s in Caddyfile lines 39-40. Simple config change. No new comments or activity since last triage.🤖 Triage Summary
Status: Confirmed — legitimate MEDIUM severity bug.
Labels: bug ✅
Assignee: akiba ✅
Next Steps
read_timeoutandwrite_timeoutfrom 30s to 60s in Caddyfile lines 39-40Severity Assessment
Correctly assessed as Medium. This causes intermittent availability degradation for slow endpoints. The fix is low-risk and should be straightforward.
Triage Assessment: MEDIUM severity
This is a valid race-condition bug. When both retries are consumed, the backend takes exactly 30s — matching Caddy's read/write timeout and causing intermittent 504s.
Labels: bug ✅
Assignee: akiba ✅
Recommended next steps:
FIXED — Commit
122c408Fix: Changed all
read_timeout 30s→read_timeout 60sandwrite_timeout 30s→write_timeout 60sin Caddyfile (9 blocks: SW routes, main proxy, stats subdomain, metrics, etc.).This eliminates the race condition where Caddy's 30s timeout exactly matched the backend's max 30s (15s × 2 retries). With 60s, even if both retries are consumed, Caddy has a 30s safety buffer.
Deployed via start.sh — Caddy reloaded.