Skip to content

[Medium] No timeout on SSE/LLM stream — hung connections held indefinitely #100

@bmersereau

Description

@bmersereau

Problem

backend/src/routes/chat.tsPOST /chat opens an SSE stream and awaits runLLMStream() with no timeout:

res.setHeader("Content-Type", "text/event-stream");
res.flushHeaders();
const { fullText, events } = await runLLMStream({ ... });  // no timeout or AbortSignal

If the upstream LLM API stalls (network partition, provider outage), the SSE connection stays open indefinitely. Under load, a wave of stalled requests can exhaust the process's open-connection limit.

The same applies to POST /projects/:projectId/chat and POST /tabular-review/:reviewId/generate.

Fix

Wrap the LLM call in a timeout using AbortController (e.g., 3 minutes). On timeout:

  1. Abort the upstream request.
  2. Write an error SSE event ({ type: "error", message: "Request timed out" }).
  3. Write data: [DONE] and end the response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions