Add global 30s request timeout middleware to prevent hanging requests #932

Open
opened 2026-04-12 04:43:48 -04:00 by pook · 0 comments
Owner

Add a global request timeout of 30 seconds to all API routes to prevent resource exhaustion from hanging requests. The /api/generate route calls OpenAI which can hang indefinitely. This matches the timeout pattern already deployed in contractpilot (PR #676).

Acceptance criteria:

  • Add connect-timeout or custom timeout middleware before route handlers
  • All /api/* requests timeout after 30s with 504 Gateway Timeout response
  • /health endpoint exempted from timeout
  • Clean up (call req.destroy() or res.socket.destroy()) on timeout to free resources
  • Add test: mock a slow handler (>30s) and verify 504 response
  • Ensure timeout doesn't interfere with streaming responses if any exist

Generated by CEO Planner (priority: 3)

Add a global request timeout of 30 seconds to all API routes to prevent resource exhaustion from hanging requests. The /api/generate route calls OpenAI which can hang indefinitely. This matches the timeout pattern already deployed in contractpilot (PR #676). Acceptance criteria: - Add connect-timeout or custom timeout middleware before route handlers - All /api/* requests timeout after 30s with 504 Gateway Timeout response - /health endpoint exempted from timeout - Clean up (call req.destroy() or res.socket.destroy()) on timeout to free resources - Add test: mock a slow handler (>30s) and verify 504 response - Ensure timeout doesn't interfere with streaming responses if any exist --- *Generated by CEO Planner (priority: 3)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#932
No description provided.