Repository navigation
Description
Description
On Windows 11, opencode web --port 4096 (and opencode serve --port 4096) fails with only:
Error: Unexpected error
ServeError
This is the same generic output reported in #46263 / #48784 / #43110 / #38738, but the underlying situation here is different and much harder for a user to diagnose: the port is held by an orphaned socket whose owning process no longer exists, so no listener can be found and killed.
Diagnostics
> netstat -ano | findstr :4096
TCP 127.0.0.1:4096 0.0.0.0:0 LISTENING 26524
TCP 127.0.0.1:4096 127.0.0.1:7914 CLOSE_WAIT 26524
TCP 127.0.0.1:4096 127.0.0.1:8583 CLOSE_WAIT 26524
... (several more CLOSE_WAIT entries)
> tasklist /FI "PID eq 26524"
INFO: No tasks are running which match the specified criteria.
> powershell> Stop-Process -Id 26524 -Force
Stop-Process : Cannot find a process with the process identifier 26524.
The TCP table still has a LISTENING entry attributed to PID 26524, but that PID is not in the process table (tasklist, Get-Process, Get-CimInstance Win32_Process all empty). Sysinternals handle64.exe cannot map the socket back to a live owner either (AFD socket handles are reported as \Device\Afd with no port information).
A raw bind test proves this is a real address conflict and not an opencode bug:
TcpListener(127.0.0.1, 4096).Start() -> SocketException WSAEADDRINUSE (10048)
"Only one usage of each socket address (protocol/network address/port) is normally permitted"
TcpListener(127.0.0.1, 4097).Start() -> OK
opencode serve --port 4097 -> starts fine, serves requests
opencode serve --port 4096 -> Error: Unexpected error / ServeError
Get-NetTCPConnection also reports a stale CreationTime for this socket (it predates the last system boot), which points at an orphaned/duplicated socket handle kept alive by another process (a firewall/HIPS or shell-injection tool that duplicated the handle, in my case).
Environment
- OpenCode
1.18.31(scoop install) - Windows 11 build 26200.9457 (PowerShell 5.1, Windows Terminal)
Steps to reproduce
- Start
opencode web --port 4096, then terminate it in a way that leaves a duplicated/inherited socket handle behind (the port ends up attributed to a PID that no longer exists). opencode web --port 4096again.- Observe
Error: Unexpected error / ServeErrorwith no errno, no address/port, no hint that the port is occupied.
What would help
- Surface the underlying listen errno and the bound address/port, e.g.
EADDRINUSE/WSAEADDRINUSE: 127.0.0.1:4096 already in use. opencode serve: bind failures print bare "Unexpected error / ServeError" — the listen errno is never surfaced #38738/opencode serveshows "Unexpected error" with no details when startup fails #48784 already describe this part. - When
--portis explicitly given and the bind fails, say so clearly instead ofServeError, and on Windows point atnetstat -ano | findstr :<port>. - Detect the Windows-specific case where the TCP table shows a
LISTENINGentry whoseOwningProcessno longer exists and print it explicitly, e.g.port 4096 is held by a stale/orphaned socket (owner PID 26524 is gone); a reboot is required to clear it. - Optionally, when a fixed
--portcannot be bound, offer/perform a fallback to a free port and print the URL it actually used (with a note that the browser origin changes, which resets web-UI local settings).
Note that #49006 (VS Code extension hardcoding --port=4096) makes this failure mode more likely to hit users, since 4096 becomes a hot port.
Activity
github-actions commentedon Sep 28, 2026
This issue might overlap with existing issues. Please check:
opencode serverestart fails withServeErrorwhen a dead PID still appears to hold the listening port.webandserveshow a generic error when the requested port is already in use.ServeErrorwith no useful details.The orphaned-socket cause described here may be distinct, but these issues cover closely related symptoms and error reporting.
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊