Skip to content

desktop: background service spawn fails "port in use" on Windows/WSL2 mirrored networking — app stuck at logo, error not logged #55907

Open

Description

@zhangzp0127

Summary

On Windows with WSL2 in mirrored networking mode, the desktop app's background service (opencode-cli.exe serve --service) repeatedly fails to start: multiple concurrent spawns race for the fixed managed service port, failed spawns are surfaced as a fatal Desktop IPC handler failed error, and the app gets stuck at the logo. The underlying bind error is never logged to main.log.

Environment

  • Desktop app: 2.0.29 and 2.0.30 (both affected)
  • Bundled CLI: 2.0.29 / 2.0.30 (opencode-cli.exe serve --service)
  • OS: Windows 11 Home x64 (build 10.0.26300)
  • WSL: 3.0.3.0, distro Ubuntu (running), kernel 6.18.54.1-microsoft-standard-WSL2
  • .wslconfig: networkingMode=Mirrored + [experimental] hostAddressLoopback=true
  • A WSL-side shared service (opencode serve --service, v2.0.30) runs inside the distro on 127.0.0.1:49374; mirrored loopback (hostAddressLoopback=true) exposes it to Windows at 127.0.0.1:49374

Reproduction

  1. Install the desktop app on a machine where the WSL distro runs the opencode shared service (or where the managed service port is otherwise occupied on Windows loopback)
  2. Launch the desktop app (cold start, or restart while the previous sidecar is still shutting down)
  3. main.log shows v2 CLI background service starting { reason: 'missing' } — repeated, with no service ready
  4. Windows-side service log shows repeated errors:
    Managed service port <N> on 127.0.0.1 is already in use by another process. Configure another port with \opencode service set port ` ...`
  5. App stuck at logo / error dialog: Desktop IPC handler failed → Server process exited with code 1

Observed on both default ports:

  • 2.0.29 (49374): collides with the WSL-side service exposed on Windows loopback via mirrored networking
  • 2.0.30 (45278): the app's own concurrent spawns race for the port — at least one instance binds and serves (visible in the log: /api/event requests served), while later duplicate spawns fail with 45278 already in use; Service.ensure surfaces the failed duplicate as fatal instead of adopting the serving instance

Expected Behavior

  • Spawn attempts are serialized; a running compatible instance is adopted (or waited on) instead of racing
  • If a spawn fails to bind, the underlying error is logged to main.log and surfaced gracefully (window loads, connection retried) instead of a silent abort / stuck logo

Actual Behavior

  • Service.ensure treats a failed spawn as fatal; the underlying bind error is never written to main.log
  • App stuck at logo; error dialog: UnknownError: An error occurred in Effect.tryPromise → Server process exited with code 1

Additional Context

Activity

  1. opencode-agent commented on Oct 16, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and logs. I couldn't reproduce this here because it needs the Windows desktop app with WSL2 mirrored networking, which this sandbox can't provide. On Linux with 2.0.30, six opencode service start runs at the same time all connected to one service without a port conflict. So the duplicate starts you saw probably come from the desktop app's startup path or from Windows itself, not the shared client. A maintainer with a Windows + WSL2 setup will need to look at it.

    Related issues, most closely related first:

    In the meantime, setting a free port in service.json (or with opencode service set port <port>), as you found, works around it.

  2. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    Thanks for the detailed report. Since 2.0.30 the Windows default port (45278) sits inside the usual WSL mirrored reservation (44620–48715), so we'd like to check whether that's part of what you saw:

    1. Does it still happen on Desktop 2.0.32?
    2. The output of wsl cat /proc/sys/net/ipv4/ip_local_port_range while it fails.
    3. Do you have a proxy configured (on Windows, or autoProxy in .wslconfig)?
    4. Does opencode service set port <port outside that range> (with the bundled CLI) fix it?
  3. zhangzp0127 commented on Oct 20, 2026

    @zhangzp0127
    Author

    感谢跟进。按你列的 4 点补充信息:

    1) 2.0.32 上是否仍复现:
    在 Desktop 2.0.29(默认 49374)和 2.0.30(默认 45278,来自 #55547)上均复现。2.0.32 未测——桌面在排查过程中被卸载,目前未安装,可以随时重装复测。

    2) 临时端口范围:

    wsl cat /proc/sys/net/ipv4/ip_local_port_range
    → 44620 48715
    

    默认服务端口 45278 正好落在这个范围内,与 #55918 的发现一致。

    3) 代理:
    未配置任何代理——Windows 系统代理 ProxyEnable=0,.wslconfig 中无 autoProxy,也未设置 HTTP(S)_PROXY 环境变量。

    4) service set port 修复测试:
    尚未用桌面内置 CLI 实测 opencode service set port <port outside range>(桌面已卸载)。但等效方案已验证有效:在 %USERPROFILE%\.config\opencode\service.json 显式指定范围外端口({"port": 49376})后,服务可正常启动,桌面恢复可用。

    补充一点:#55918 的独立绑定测试(.NET TcpListener 直接绑定 45278 失败、无任何进程占用、邻近端口正常)与我们观察到的现象完全吻合,支持“镜像模式 HNS 临时端口预留”这一根因判断。如果需要,我可以重装桌面 2.0.32 并实测 service set port 的修复效果后回来同步结果。

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions