GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — service: Windows-reserved (excluded) port is reported as "already in use by another process" · Issue #66963 · anomalyco/opencode

service: Windows-reserved (excluded) port is reported as "already in use by another process" #66963

New issue
Copy link
New issue
Copy link
Backlog
#66966
Backlog
service: Windows-reserved (excluded) port is reported as "already in use by another process"#66963
#66966
Copy link
Labels
area/serviceBackground service and serverplatform/windowsWindowstype/bugSomething is brokenversion/v2OpenCode 2.x

Description

@igorsaevets
igorsaevets
opened on Nov 28, 2026
Issue body actions

Description

On Windows, if the service port is inside a TCP range that Windows has excluded, opencode service start reports it as in use by another process. Nothing holds it: netstat -ano shows no socket on the port, and bind() fails with WSAEACCES (10013). People then look for a process that does not exist (#53351, #55086, #55918).

Moving the default below 49152 (#55547, #57428, #66613 for WSL) helps only with Windows' default dynamic port range, 49152-65535. Here the range starts at 1024, and Hyper-V/WinNAT blocks sit below 32768 too (list below). A Visual Studio install has left the same setting on GitHub's Windows runner image (discussion). The configured port here, 19478, is in one of the blocks, and nothing keeps 28894 or 24798 out of them on such a machine.

The error cannot tell the two cases apart: Bun creates Failed to start server. Is port N in use? with code: "EADDRINUSE" for every listen failure except EACCES on Linux (mod.rs), and PortOwner.describe returns undefined on Windows (port-owner.ts).

Suggestion: on Windows, after a failed bind, check netsh interface ipv4 show excludedportrange protocol=tcp (no admin needed) and say that Windows reserved the port, with the range; netstat -ano -p TCP gives the PID when a process holds it. The docs line "Windows reserves ports from 49152 up" (web.mdx) holds only for the default range.

The reserved-port message was suggested in a comment on #54267; that issue is about a service that has not exited, so this one is separate. Related: #50672.

Plugins

None (fresh config in a scratch home folder)

OpenCode version

2.4.2 (@opencode/cli from npm, the current latest). Code links are to dev at e1b5c45.

Steps to reproduce

  1. Check the dynamic port range and the exclusions (no admin needed):
    > netsh int ipv4 show dynamicport tcp
    Start Port      : 1024
    Number of Ports : 64511
    
  2. Pick a port inside one of the excluded blocks: opencode service set port 19478 (block 19405-19504).
  3. opencode service start fails after about 20 s:
    Error: Server process exited with code 1
    Error: Managed service port 19478 on 127.0.0.1 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again.
      [cause]: ServeError:
        ...
        [cause]: Error: Failed to start server. Is port 19478 in use?
            at serve (unknown)
            at <anonymous> (node:_http_server:438:35)
    
  4. netstat -ano -p TCP has no :19478 line; a plain bind() to 127.0.0.1:19478 fails with WSAEACCES (10013).
  5. With opencode service set port 19620 (outside the blocks), opencode service start prints http://127.0.0.1:19620 at once.
netsh int ipv4 show excludedportrange protocol=tcp on this machine
Start Port    End Port
----------    --------
      5357        5357
     13508       13508
     18905       19004
     19005       19104
     19105       19204
     19205       19304
     19305       19404
     19405       19504
     19505       19604
     19663       19762
     25399       25498
     25510       25609
     38498       38597
     49823       49922
     50000       50059     *
     50060       50159
     50160       50259
     50260       50359
     50360       50459
* - Administered port exclusions.

Screenshot

No response

Operating System

Windows 11 Pro 10.0.26200

Terminal

Not terminal-specific: opencode service start fails before any UI (reproduced from a script).

Activity

  1. opencodejr
    added
    area/serviceBackground service and server
    platform/windowsWindows
    type/bugSomething is broken
    version/v2OpenCode 2.x
    on Nov 28, 2026
  2. opencodejr commented on Nov 28, 2026

    @opencodejr
    opencodejrBot
    on Nov 28, 2026
    Contributor
    More actions

    Thanks for the detailed report. I couldn't reproduce this here: it needs Windows with an excluded TCP port range, and my environment only runs Linux, which has no excluded port ranges.

    On the latest dev (8870cab), the code that produces this message has not changed. When the bind still fails after the retries, the service reports the port as already in use by the process it found, or another process if it found none. On Windows, the lookup for that process returns nothing straight away, so the message always says another process. Whether a reserved port reaches that path depends on Bun reporting WSAEACCES as EADDRINUSE, as your error output shows; I could not check that here.

    A maintainer with a Windows machine will need to confirm it. Your steps already cover what they need: an excluded range from netsh int ipv4 show excludedportrange protocol=tcp, opencode service set port with a port inside it, and opencode service start.

    Related issues and pull requests:

    • Windows: managed service fails when default port 49374 is in an excluded TCP range #53351, Windows CLI: WSL2 镜像网络预留范围内的 45278 导致服务启动失败,端口查询无占用记录 #55918: the same message on earlier default ports; both were resolved by moving the default port, not by changing the message
    • service: relaunch fails with "Managed service port already in use" when previous background service has not exited #54267: where a reserved-port message was suggested
    • docs: WSL default port 49374 falls inside Windows reserved range, so pair links fail in a Windows browser #62532 and open PR fix(cli): move the WSL service port out of the Windows reserved range #66613: the WSL default port in the Windows reserved range
    • service: hardcoded default port 49374 locks out any second client on shared loopback (multi-user/WSL mirrored), surfacing only a generic timeout #50672, service: default port 49374 collides with ephemeral TCP source ports #62891: other problems with the fixed default port
  3. argszero commented on Nov 28, 2026

    @argszero
    argszero
    on Nov 28, 2026
    Contributor
    More actions

    I'd like to work on this.

    Reading packages/cli/src/server-process.ts:142 and packages/cli/src/services/port-owner.ts on dev, the message is produced whenever the listen fails and no owner is found, and PortOwner.describe returns nothing on Windows, so WSAEACCES (10013) and a real holder look identical there.

    Plan: on Windows only, when the listen fails and no owner is found, read netsh interface ipv4 show excludedportrange protocol=tcp (and the ipv6 list when it covers the port) and report that Windows reserved the port, naming the range, instead of the "already in use by another process" wording. When a process does hold the port, the current message stays. The netsh output parsing goes into a small pure function so it can be unit tested without Windows, covering reserved, held, and netsh-unavailable.

    One question before I build: is an extra netsh call on a failed start acceptable to you, or would you rather the message stay generic and only the docs line change?

  4. fanyzp commented on Nov 28, 2026

    @fanyzp
    fanyzp
    on Nov 28, 2026
    More actions

    Confirmed, this is a real bug in the error path, not a wrong diagnosis of the port state.

    I checked the code: on Windows PortOwner.describe returns undefined unconditionally (packages/cli/src/services/port-owner.ts), so server-process.ts always falls back to "already in use by another process" when a managed-service bind fails with EADDRINUSE. A port in an excluded range can never have a listener, so that message sends people hunting for a process that does not exist, exactly as you describe. Your netstat + bind() WSAEACCES evidence matches: nothing holds 19478, Windows just refuses the bind.

    I am working on a fix: after a failed bind on Windows, check netsh interface ipv4 show excludedportrange protocol=tcp and report the port as Windows-reserved with the range, instead of claiming another process holds it. Will link the PR here when it is up.

  5. igorsaevets commented on Nov 28, 2026

    @igorsaevets
    igorsaevets
    on Nov 28, 2026
    Author
    More actions

    Checked the open point from the bot on this machine: opencode 2.4.2 runs Bun 1.4.4 (BUN_BE_BUN=1 opencode --version), and its Bun.serve reports an excluded port and a held port the same way, while node:net in the same runtime does not:

    listen on 127.0.0.1 excluded port (19478) port another process listens on (19620)
    Bun.serve EADDRINUSE, errno 0 EADDRINUSE, errno 0
    node:net EACCES, errno 10013 EADDRINUSE, errno 10048

    So a node:net listen on the port after the failure could tell the two cases apart without netsh. If netsh stays in the plans above: its header text depends on how it is started. On this Windows with a Russian display language it printed Russian headings when started from Python and English ones when started from Bun or pwsh, so matching only the rows of two numbers is safer than matching Start Port.

    Probe: BUN_BE_BUN=1 opencode probe.mjs 19478 19620 while another process listens on 19620
    import net from "node:net"
    for (const port of process.argv.slice(2).map(Number)) {
      try {
        Bun.serve({ port, hostname: "127.0.0.1", fetch: () => new Response() }).stop(true)
        console.log(port, "Bun.serve ok")
      } catch (e) {
        console.log(port, "Bun.serve", e.code, e.errno)
      }
      await new Promise((done) => {
        const srv = net.createServer()
        srv.once("error", (e) => (console.log(port, "node:net", e.code, e.errno), done()))
        srv.listen(port, "127.0.0.1", () => (console.log(port, "node:net ok"), srv.close(), done()))
      })
    }
    19478 Bun.serve EADDRINUSE 0
    19478 node:net EACCES 10013
    19620 Bun.serve EADDRINUSE 0
    19620 node:net EADDRINUSE 10048
    
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

    area/serviceBackground service and serverplatform/windowsWindowstype/bugSomething is brokenversion/v2OpenCode 2.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.