Skip to content

[BUG] WebSocket connection timeout of 800ms too short — causes premature SSE fallback on slow networks #748

Description

@vipul674

Description of the Bug

In frontend/src/components/chat/ChatPanel.tsx, the WebSocket connection has a timeout of only 800ms:

const wsTimeout = setTimeout(() => {
    // WebSocket didn't connect fast enough, fall back to SSE
    setIsWsConnected(false);
    startSSE();
}, 800);

An 800ms timeout is too aggressive for WebSocket connections. WebSocket connections require:

  1. DNS resolution (can take 100-500ms on slow networks)
  2. TCP handshake
  3. HTTP upgrade handshake
  4. Server-side processing time

On slow networks, cold-start servers, or under load, this can easily exceed 800ms, causing the application to unnecessarily fall back to SSE streaming. This means users lose the benefits of real-time WebSocket streaming (lower latency, full-duplex) even though WebSocket would have worked fine given an extra second or two.

Steps to Reproduce

  1. Connect to the application over a slow network (e.g., mobile 3G, throttled connection)
  2. Start a chat session and send a message
  3. The WebSocket connection attempt times out at 800ms
  4. The client falls back to SSE, losing real-time streaming benefits
  5. WebSocket would have succeeded with a longer timeout

Expected Behavior

The timeout should be increased to at least 5000ms (5 seconds) to account for network and server startup latency. A retry mechanism should also be considered before falling back.

Affected File

frontend/src/components/chat/ChatPanel.tsx (line ~283)

Suggested Fix

Increase the timeout:

const WS_TIMEOUT_MS = 5000;  // 5 seconds instead of 800ms

Consider adding a single retry attempt before falling back to SSE.

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssocGirlScript Summer of Code 2026 issue/PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions