Skip to content

ECONNRESET when using Custom Provider: socket connection closed unexpectedly and custom server not detected correctly #51537

Closed as not planned

Description

@es1144t

Description

Description
I am encountering repeated ECONNRESET errors when using a Custom Provider to connect to an OpenAI-compatible AI server. The error occurs during chat with the selected AI model and causes the response stream to terminate unexpectedly.

The app also seems unable to correctly detect or handle the custom provider endpoint. This does not appear to be a transient network issue because official providers (e.g., OpenAI, Anthropic) work fine under the same network conditions.

Steps to Reproduce
Start an OpenAI-compatible server at http://:/v1 (e.g., vLLM, SGLang, Ollama, etc.).

Add a Custom Provider in the app with the server URL and model name.

Start a new chat session using this custom provider.

Send a chat request or upload files (without exceeding the model context limit).

After a few interactions, the response stops and the ECONNRESET error appears.

Repeat the same steps with an official provider to confirm the issue is specific to the custom provider.

Environment
OS: <e.g., Windows 11 / macOS 15 / Ubuntu 22.04>

App Version: <e.g., 1.18.25 or latest>

Terminal: <e.g., PowerShell / CMD / Bash / Zsh>

Custom Provider Type: <e.g., SGLang / vLLM / Ollama / OpenAI-compatible>

Model: <e.g., Qwen3.5-27B-FP8>

Endpoint: http://:/v1 (no proxy or load balancer)

Error Logs
text
[ERROR] service=llm providerID=custom
error={"error":{"code":"ECONNRESET","path":"http://:/v1/chat/completions","errno":0}}
stream error
[ERROR] service=session.processor
error=The socket connection was closed unexpectedly.
For more information, pass verbose: true in the second argument to fetch()
In some cases, the app enters an endless retry loop:

text
Connection reset by server, retrying in 25s - attempt #21
Expected Behavior
The app should correctly detect and manage the Custom Provider.

When the socket connection is closed unexpectedly, it should show a clear user-friendly error instead of a raw fetch() error.

It should use a proper retry mechanism with backoff, not an infinite retry loop.

Timeout and retry behavior should be configurable.

Additional Context
The issue only occurs with custom providers; official providers work normally.

Disabling reasoning-parser or reasoning features on the server side avoids the error, but this is not suitable for agentic use cases.

The problem seems to be in the transport/streaming client layer, possibly related to HTTP/2 or keep-alive connection handling.

The app may be treating ECONNRESET as a non-retryable error and terminating the session too early.

Screenshots / Share Link

I can provide more logs or test specific configurations if needed.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Sep 26, 2026

    @github-actions
    Contributor

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

    • #22803: Very similar SGLang/OpenAI-compatible provider ECONNRESET during Qwen reasoning streams, including the same retry loop and reasoning workaround.
    • #46088: ECONNRESET when using an independently deployed custom model.
    • #41848: Stream errors can cause an unbounded retry loop.
  2. seankoji commented on Oct 16, 2026

    @seankoji

    A deterministic repro for the custom-provider ECONNRESET case, in case it helps separate gateway restarts from the streaming resets reported above.

    Setup: OpenCode 2.0.30 (also seen on 2.0.26 and 2.0.29), opencode serve on localhost driven by a client (T3 Code), and a custom OpenAI-compatible provider pointing at a self-hosted LiteLLM proxy on another machine. Model: DeepSeek V4.1 Flash through LiteLLM.

    Steps:

    1. Start several sessions on the LiteLLM-backed model and keep them mid-turn (I had about 15 running at once).
    2. Recreate the LiteLLM container (docker compose up -d with a changed image or config). It is back and healthy, with /health/liveliness returning OK, within about a minute.

    Result: every in-flight session ends with:

    level=ERROR message="Failed to drain Session" cause="AI.Error: ECONNRESET: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()"
    

    The session's turn is failed rather than retried, even though the provider is reachable again seconds later. On 16 October 2026 this happened twice (about 01:15Z and 01:51Z), and 4 of 18 sessions failed this way. Across four days of logs on one machine there were 56 Failed to drain Session errors; provider transport errors were 87 of 131 assistant errors in the database (ConnectionRefused 33, ECONNRESET 25, timeouts 16).

    A related variant (2.0.26): if the proxy port refuses connections while starting up, OpenCode retries silently for about 90 seconds, then logs Failed to drain Session ... ConnectionRefused only to opencode.log. The client never receives an error event and shows the session as busy.

    What would help: treat ECONNRESET and ECONNREFUSED on custom providers as retryable with backoff, at least before any tokens of the response have streamed, and emit a session error the client can see when retries are exhausted.

  3. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the report! Several fields in the template are still placeholders, so we can't tell yet which setup this happens on. Could you tell us, in your own words and briefly:

    • The output of opencode --version. This tells us whether you're on v1 (opencode-ai, 0.x/1.x) or v2 (@opencode/cli, 2.x).
    • Your OS and how you installed OpenCode.
    • The server you're actually using (vLLM, SGLang, Ollama, …), its version and the reasoning-parser flags, plus the exact model.
    • Your custom provider config from opencode.json (leave out API keys).
    • What you did right before the reset, e.g. a long agentic run with tool calls, a file upload or a plain chat, and roughly how far into the session it happened.
    • The full log around the error, if you have it.

    You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.

  4. opencodejr commented on Oct 31, 2026

    @opencodejr
    Contributor

    We haven't heard back, so I'm closing this for now. We still don't know your OpenCode version (opencode --version), your OS, which server you used (vLLM, SGLang or Ollama) and its reasoning-parser settings, the model, or your provider config. Without those we can't tell whether this is v1 or v2, and we can't reproduce the ECONNRESET resets.

    If it still happens, please reply here with those details, or open a new issue with them. We'll be happy to look again. Thanks!

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions