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 — fix(cli): name windows-reserved port range in managed service bind error by fanyzp · Pull Request #66966 · anomalyco/opencode

Conversation

@fanyzp

@fanyzp fanyzp commented Nov 28, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #66963

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows, if the managed service port falls in a TCP range Windows has excluded (Hyper-V, WinNAT), opencode service start reports the port as "already in use by another process". Nothing holds the port: netstat shows no socket and bind() fails with WSAEACCES, so the message sends people hunting for a process that does not exist.

The cause is in the error path: on Windows PortOwner.describe returns undefined unconditionally, so server-process.ts always falls back to "another process" when a bind fails with EADDRINUSE.

This change checks, after a failed bind on Windows, netsh interface ipv4 show excludedportrange protocol=tcp (no admin needed) and reports the port as Windows-reserved with the range instead, for example:

Managed service port 19478 on 127.0.0.1 is reserved by Windows (excluded port range 19405-19504). No process is using it.

A reserved port can never gain a listener, so the check also fails fast instead of waiting out the 15 second incumbent retry. The docs line claiming Windows only reserves ports from 49152 up is corrected, since Hyper-V and WinNAT exclusions can sit below that.

How did you verify your code works?

  • bun test test/service.test.ts in packages/cli: 34 pass, 0 fail, including two new tests. One feeds the netsh output from the issue through the range parser (in-range, range edges, administered * range, out-of-range, empty output); the other checks the lookup returns nothing off Windows.
  • bun run check from the repo root: 37 tasks successful, no type errors.
  • bun typecheck and bun run build from services/site: clean, 1926 pages built.
  • The full suite above passed three consecutive times with no changes in between.

One limit: this machine runs Linux, so the netsh call itself was verified by code inspection and the parser test, not by an actual Windows run. The Windows-only path is guarded by a platform check and returns nothing on other platforms.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #62891

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fanyzp
fix(cli): name windows-reserved port range in managed service bind error
c60e707
opencodejr[bot]
opencodejr Bot reviewed Nov 28, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound. I couldn't run it on Windows, but I ran the parser and the netsh lookup with process.platform set to win32 and a fake netsh printing Windows-style output (CRLF line endings, the header lines and an administered * range). It returned the right range for ports inside one and nothing for ports outside. test/service.test.ts passes and tsc -b is clean. A maintainer with Windows should still confirm the real case from #66963 (an excluded range added with netsh, then opencode service start).

Public API: unchanged. Only the wording of the CLI error changes, plus a new internal PortOwner helper.

One small point on the docs, noted inline.

Related: #62891

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread services/site/src/docs/content/cli/web.mdx Outdated
Windows reserves ports from 49152 up, and WSL mirrored networking reserves
another block below that. Print the current address with
`opencode service status`:
Windows can also reserve port ranges below 49152, for example for Hyper-V or

@opencodejr opencodejr Bot Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This drops the reason the Windows default port is different (28894): Windows hands out 49152 and up for outgoing connections, and WSL mirrored networking reserves a block below that (see defaultPort in service-config.ts). The old sentence wasn't wrong, just incomplete. Could you keep it and add the Hyper-V/WinNAT point next to it, rather than replacing it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fanyzp fanyzp Nov 28, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. The docs now keep the original explanation for why Windows defaults to 28894 and add the Hyper-V/WinNAT point next to it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@opencodejr opencodejr Bot Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I checked 3b076f5: the reason for the 28894 default is back. One small thing in the new sentence: "Hyper-V and WinNAT also reserve blocks of that range at boot, so a port outside the default dynamic range can still be unavailable" contradicts itself. "That range" points back to 49152 and up, but the point is that these reservations can also sit below it (as in #66963, 19405-19504). Something like "Hyper-V and WinNAT can also reserve blocks below 49152" would say it. Nothing else from my review is outstanding.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fanyzp fanyzp Nov 28, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 67f95cb — the sentence now reads "Hyper-V and WinNAT can also reserve blocks below 49152 at boot", so it no longer implies the reservations sit inside the 49152+ range.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@opencodejr opencodejr Bot Nov 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I checked 67f95cb in my last review: the sentence now correctly says these reservations can sit below 49152. Nothing else is outstanding on the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fanyzp
docs(cli): keep windows default port explanation in service docs
3b076f5
opencodejr[bot]
opencodejr Bot reviewed Nov 28, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs point is addressed: the reason for the 28894 Windows default is back, with the Hyper-V/WinNAT note added next to it. Nothing else changed since my last review. The public API is still unchanged; only the wording of the CLI error changes. A maintainer with Windows should still confirm the real case from #66963.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fanyzp
docs(cli): fix hyper-v and winnat port reservation wording
67f95cb
opencodejr[bot]
opencodejr Bot reviewed Nov 28, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs points are addressed: the reason for the 28894 Windows default is back, and the Hyper-V/WinNAT sentence now correctly says these reservations can sit below 49152. Nothing else changed. The public API is still unchanged; only the wording of the CLI error changes. A maintainer with Windows should still confirm the real case from #66963.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@igorsaevets

igorsaevets commented Nov 28, 2026

Copy link
Copy Markdown

Tested this branch (67f95cb) on the Windows 11 machine from #66963, running the CLI from source with Bun 1.4.4 (bun run --cwd packages/cli src/index.ts) in a scratch home. For the comparison, the same checkout with the two src files switched back to the merge base 8870cab:

opencode service start on 127.0.0.1 this branch merge base 8870cab
19478, inside the excluded range 19405-19504 is reserved by Windows (excluded port range 19405-19504). No process is using it., exit 1 after about 3 s is already in use by another process., exit 1 after 22 s
19621, another process listening on it is already in use by another process., exit 1 after 22 s not run
19620, free starts, http://127.0.0.1:19620 not run

netsh interface ipv4 show excludedportrange protocol=tcp took 42-137 ms in 20 runs here, well inside the lookup's 1 second timeout. This Windows has a Russian display language: netsh prints localized headers when started from Python, and the row-only pattern still parsed all 19 ranges.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This branch has not been deployed

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

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@fanyzp @igorsaevets
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.