Skip to content

[Bug]: Process crashes with "setRawMode failed with errno: 5 (EIO)" when terminal disconnects #15286

Closed

Description

@philperron

Description

OpenCode crashes hard (no graceful shutdown) when the controlling terminal is lost. This manifests as repeated forced session logouts with no recovery.

Reproduced 4+ times in a single day on the same machine.

Environment

  • OpenCode version: 1.2.15
  • OS: Ubuntu 24.04, kernel 6.17.0, x86_64
  • Terminal: GNOME Terminal

Log evidence

The crash in ~/.local/share/opencode/log/2026-02-25T180946.log:

ERROR 2026-02-25T18:11:05 +78848ms service=default e=setRawMode failed with errno: 5 exception
ERROR 2026-02-25T18:11:05 +0ms service=default Error: setRawMode failed with errno: 5

The log ends abruptly at those two lines. A normal/clean shutdown produces a full teardown sequence (shutting down, disposing all instances, state disposal completed, etc.) — none of that is present here.

errno 5 = EIO (Input/Output Error) on a TTY, raised when the process loses its controlling terminal (e.g. the terminal window is closed or crashes while OpenCode is running).

Expected behavior

OpenCode should catch the EIO/errno 5 error on setRawMode and shut down gracefully, preserving session state, rather than crashing hard.

Steps to reproduce

  1. Start OpenCode in GNOME Terminal
  2. Close or crash the terminal window while OpenCode is running
  3. On relaunch, session is lost

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Feb 26, 2026
  2. github-actions commented on Feb 26, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or closely related to an existing issue. Please check:

  3. papajade55-debug commented on Apr 23, 2026

    @papajade55-debug

    Additional symptom in v1.14.21: opencode.json truncated to 0 bytes on EIO shutdown

    Same setRawMode errno: 5 crash, but with a secondary data-loss side effect — the config file gets wiped to 0 bytes.

    Reproduction (100% reliable on my machine):

    1. Start opencode TUI (v1.14.21, Linux)
    2. Close/exit normally (no terminal crash required)
    3. ls -la ~/.config/opencode/opencode.json → 0 bytes

    Log evidence (consecutive cycles):

    ERROR service=server-proxy e=setRawMode failed with errno: 5 exception
    ERROR service=server-proxy error=setRawMode failed with errno: 5 process error
    INFO  service=server-proxy worker shutting down
    INFO  service=server-proxy disposing all instances
    

    The file mtime matches the shutdown timestamp to the second. Confirmed across two independent test cycles.

    Hypothesis: a shutdown finalizer attempts to serialize the loaded config back to disk after the EIO fault, but writes empty content due to the degraded state.

    Workaround: chmod 444 ~/.config/opencode/opencode.json — the readonly bit prevents the faulty write; plugin loading (path=opencode-tool-search loading plugin confirmed in log) and normal runtime work fine. To edit the file later, chmod 644, modify, then chmod 444 again before relaunch.

    Environment: opencode 1.14.21, Linux Mint 22.3 (Ubuntu 24.04), kernel 6.17.0, Node v24.13.1, GNOME Terminal.

    This suggests the fix for this issue should not only handle EIO gracefully but also ensure the config-save path is guarded against writing empty/partial state during abnormal shutdown.

  4. juleslemee commented on May 26, 2026

    @juleslemee

    @thdxr had the same exact log signature from a crash yesterday on 1.15.10. Opus 4.7 : "looking at your log, you have worker shutting down between the EIO errors, which the original reporter didn't. That suggests opencode now attempts graceful shutdown on EIO instead of crashing hard, but it still has to exit (terminal's gone). The fix addressed the symptom (no graceful shutdown), not the underlying TTY-state issue that triggers EIO in the first place. Long-lived sessions and any TTY disturbance (display sleep, terminal app backgrounded, window close) will still hit it."

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)opentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions