Skip to content

fix(mcp): connection hangs with non-standard SSE/HTTP servers which causes opencode to hang #8406

Closed

Description

@ch-anandka

Description

When connecting to non-standard MCP servers over SSE or StreamableHTTP, OpenCode can hang indefinitely if the server:

  • Returns HTTP 200 but sends malformed SSE stream
  • Accepts connection but never completes MCP initialize handshake
  • Stalls during message exchange

The existing withTimeout wrapper only times out the promise but doesn't cancel the underlying HTTP/SSE connection, leaving resources
hanging.

Expected Behavior

Connection attempts should timeout gracefully and clean up resources, even if the server doesn't respond properly.

Current Behavior

OpenCode hangs waiting for server response, blocking startup or reconnection attempts.

Proposed Solution

Add AbortController support to remote MCP transports:

  • Pass AbortSignal to transport requestInit (native fetch API)
  • Call abort() on timeout to forcefully close connections
  • Ensure cleanup in all error paths

Environment

  • OpenCode version: latest (dev branch)
  • MCP server: Custom/non-standard SSE server

Activity

  1. github-actions commented on Jan 14, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. added a commit that references this issue on Jan 14, 2026
    f7bb652
  3. anandka commented on Jan 14, 2026

    @anandka

    Not a Duplicate - Different Root Cause

    Our Issue: Network-level hang when MCP servers send HTTP 200 but malformed/incomplete responses. The withTimeout wrapper rejects the promise but doesn't cancel the underlying fetch() request, leaving connections open indefinitely.

    Unique technical gap: We're adding AbortController to forcefully terminate fetch requests on timeout, which none of the above issues
    address.

    Our fix complements #8212 (handles connection timeout) and prevents scenarios like #3273 (app freezing) by failing gracefully.

  4. sandipwane commented on Jan 14, 2026

    @sandipwane
    Contributor

    Hi @rekram1-node, Can you please take a look at this issue?
    We're currently blocked on shipping an MCP feature due to the connection hanging behavior described here.

    @anandka has already raised PR with the fix: #8413. Would appreciate a review when you get a chance.

    Thanks!

  5. thdxr commented on Mar 25, 2026

    @thdxr
    Member

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions