Skip to content

ECONNRESET: The socket connection was closed unexpectedly. For more information #59291

Closed

Description

@kharitonovdo

This error happens quite often. I don’t understand why, or how to fix it. My internet connection is excellent, and it’s definitely not a hardware issue.

Activity

  1. opencode-agent commented on Oct 26, 2026

    @opencode-agent
    Contributor

    Thanks for the report! This error can come from several different causes, so we need a few details to work out which one you're hitting:

    1. OpenCode version (opencode --version), your OS, and how you installed OpenCode.
    2. Where you see the error: the TUI, the desktop app, opencode run, or a third-party front end. Please paste the full error text or a screenshot.
    3. Provider and model you're using (e.g. OpenCode Zen/Go, Anthropic, OpenAI, or a custom/OpenAI-compatible endpoint).
    4. When it happens: on the first message after OpenCode has been idle for a while, partway through a long response or tool call, after a fixed amount of time, or only in one large session.
    5. Any proxy, VPN, firewall or security/antivirus software (e.g. Zscaler, CrowdStrike) on your machine or network.
    6. If possible, the logs from a run where it happens (start OpenCode with --print-logs, or attach the log file).

    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.

    These existing issues may already cover your problem. They're ordered by likelihood:

  2. kharitonovdo commented on Oct 26, 2026

    @kharitonovdo
    Author
    Image ECONNRESET: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()

    When a task is complex and the neural network takes a long time to process it, this error occurs. How can I fix it?

  3. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the error text and the screenshot, and for noting that it happens when a task is complex and the model takes a long time to answer. That helps narrow it down.

    We still need a few details to work out which cause you're hitting, because this error has several:

    1. OpenCode version (opencode --version), your operating system, and how you installed OpenCode.
    2. Where you use it: the TUI, the desktop app, opencode run, or another front end.
    3. Provider and model (e.g. OpenCode Zen/Go, Anthropic, OpenAI, Google Vertex/AI Studio, or a custom/OpenAI-compatible endpoint).
    4. Roughly how long the model has been working when the error appears. For example, is it always about 60 seconds, or does it vary? Does it happen while the model is writing a large file or edit?
    5. Any proxy, VPN, firewall or antivirus/security software on your machine or network.
    6. If possible, logs from a run where it happens (start OpenCode with --print-logs, or attach the log file).

    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.

    These existing issues may already cover your problem. They're ordered by likelihood:

  4. magusy commented on Oct 31, 2026

    @magusy

    Following up with diagnostics from a machine that hits this regularly.

    Environment

    • OpenCode 2.2.4, desktop app for Windows (per-user install at %LOCALAPPDATA%\Programs\ai.opencode.desktop\OpenCode.exe)
    • CLI @opencode/[email protected] (npm global), so client and server versions match
    • Windows 11 Pro 21H2, 10.0.22000, x64
    • Error appears in the desktop app. The bundled background service logs it server-side in %USERPROFILE%\.local\share\opencode\log\opencode.log; there is no external proxy in front of it.

    Error text

    timestamp=2026-10-30T22:21:20.916Z level=ERROR run=<id> 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()
        at a (B:/~BUN/root/chunk-fgtjesq4.js:6:4214)
        at <anonymous> (B:/~BUN/root/chunk-4e2rqd16.js:18:6047)
        at runLoop (B:/~BUN/root/chunk-4e2rqd16.js:18:2552)
        ...
        at SessionStep.attempt (B:/~BUN/root/chunk-z20sjgqk.js:382:3574)
        at SessionRunner.runStep (B:/~BUN/root/chunk-z20sjgqk.js:382:2672)
        at SessionRunner.drain (B:/~BUN/root/chunk-4e2rqd16.js:18:2552)
        at ServerProcess.start (B:/~BUN/root/chunk-94gxrctf.js:2:7603)
      [cause]: AI.Error.Transport: ECONNRESET: The socket connection was closed unexpectedly. ...
        [cause]: TypeError: The socket connection was closed unexpectedly. ...
    } role=server sessionID=ses_...
    

    Stack trimmed for brevity; the wrapper is always Failed to drain Session, with AI.Error.Transport: ECONNRESET underneath.

    Frequency

    43 events in the current log (15.8 MB, covering 2026-09-07 04:41Z to 2026-10-31 00:56Z), all in bursts:

    UTC hour events
    2026-09-07 04 1
    2026-10-24 15 2
    2026-10-24 18 2
    2026-10-29 20 1
    2026-10-30 19 4
    2026-10-30 20 10
    2026-10-30 21 6
    2026-10-30 22 7
    2026-10-30 23 9
    2026-10-31 00 1

    37 of them fall between 2026-10-30 19:25Z and 2026-10-31 00:56Z. Gaps are irregular: from 0.2 to 103 minutes. The tightest cluster is 22:59:25Z-23:13:15Z — 12 resets in 14 minutes, sometimes 11-21 seconds apart. So this does not look like a keep-alive or idle timeout on a fixed schedule.

    When it happens

    During long streaming turns, especially tool-heavy ones with slow commands, but also on turns where the only long-lived stream is the model response itself. Short prompts do not reproduce it.

    Provider / model

    Per-event attribution is not available in the log: sessions that reset only appear in the ERROR lines, without a matching message=stream providerID=... line. Models used on this machine in the same period: opencode/big-pickle (8099 streams), opencode/hy3-free (1137), ollama/gemma4:31b-cloud (160). Providers: opencode and ollama.

    Network

    No proxy, VPN, or TLS-inspecting security product on the machine. The ISP does intermittently interfere with TLS handshakes to some domains, so a middlebox dropping long-lived connections is plausible — but the resets also happen on turns where the only long-lived stream is the model response itself.

    Impact

    Non-fatal: session state survives, but the turn aborts and has to be re-sent manually. 37 resets in one 5.5-hour session is disruptive.

    Suggestion

    #54154 (retry with backoff for transport errors) would cover most of this. Retrying idempotent streaming requests, or resuming from the last received chunk, would remove the manual step entirely.

    Happy to test a build with the retry patch.

  5. opencodejr commented on Oct 31, 2026

    @opencodejr
    Contributor

    We're closing this for now because we haven't heard back with the details we asked for: your OpenCode version, OS and install method, where you use it (TUI, desktop app or opencode run), the provider and model, and any proxy/VPN/security software or --print-logs output. This error has several possible causes, and we need those details to tell which one you're hitting.

    If it still happens, please reply with those details, or open a new issue that includes them, and we'll take another look. In the meantime, #56344, #57875 and #54160 may cover your problem, so they're worth following.

  6. omandotkom commented on Nov 10, 2026

    @omandotkom

    stupid harness. Retrying in 2s · attempt 3 · ECONNRESET: The socket connection was closed unexpectedly. For more information, pass verbose: true in the second argument to fetch()

  7. thanhchuongbmd commented on Nov 11, 2026

    @thanhchuongbmd

    Retry due · attempt 3 · ECONNRESET: The socket connection was closed unexpectedly. For more information, pass verbose: true in the second argument to fetch()
    I so

  8. neriousy commented on Nov 12, 2026

    @neriousy
    Member

    This should be fixed in the latest version. If you still see ECONNRESET after updating, please open a new issue with your opencode --version, OS, provider/model and any logs.

  9. thanhchuongbmd commented on Nov 13, 2026

    @thanhchuongbmd

    This should be fixed in the latest version. If you still see ECONNRESET after updating, please open a new issue with your opencode --version, OS, provider/model and any logs.

    still error and response token very slow (~5 token /s), version: v2.2.7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions