Skip to content

fix(service): handle unusable managed-service ports on Windows - #53355

Closed
HarshithReddyDev wants to merge 5 commits into
anomalyco:devfrom
HarshithReddyDev:fix/windows-excluded-service-port
Closed

HarshithReddyDev wants to merge 5 commits into
anomalyco:devfrom
HarshithReddyDev:fix/windows-excluded-service-port

Conversation

@HarshithReddyDev

@HarshithReddyDev HarshithReddyDev commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #52234

Type of change

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

What does this PR do?

On Windows, the default managed-service port 49374 can fall inside an excluded TCP port range. When that happens, the service cannot bind the port even though no process owns it.

The managed-service path was retrying the same unusable port instead of falling back to another available port.

This change reuses the existing available-port selection when the configured managed-service port is unbindable. The actual bound address is then used for service registration.

No Desktop-specific changes are required because Desktop already delegates managed-service startup to the CLI.

How did you verify your code works?

I reproduced the issue on Windows 11 with port 49374 inside an excluded TCP range and verified that no process was listening on the port.

The targeted regression test passes:

bun test --timeout 180000 test/service.test.ts -t "unbindable managed service port falls back to an available port"

Result: 1 passed, 22 filtered, 0 failed, 9 expects.

The full service test suite produced 22 passing tests and one pre-existing environmental timeout unrelated to this change.

git diff --check also passes.

Screenshots / recordings

Not applicable. This is a CLI/service logic change with no UI changes.

Checklist

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

… port is unbindable

On Windows, the default managed-service port can fall inside an
excluded TCP range (e.g. 49374 in 49292-49391): bind() fails with an
EADDRINUSE-typed error while no process owns the port. After the
incumbent wait expires, probe the port: a genuine collision keeps the
actionable conflict error, while a refused connection relaunches on an
automatically selected port and warns with the actual listening URL.
Registration records the real address, so Desktop and CLI discover the
running service without configuration changes.
@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@SHJordan

Copy link
Copy Markdown

Encountered this exact issue on Windows 11 (build 26300) with OpenCode v2.0.32 when running 'opencode plugin update' (default ports 45279/45280 rejected by the OS despite no active listener). Manually moving the service port to 12580 worked around it. Looking forward to having this dynamic fallback merged!

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

service: hardcoded default port 49374 with no fallback and a silent hang when it's unavailable

2 participants