Skip to content

fix: avoid browser blocked ports for the runner server - #35262

Merged
jennifer-shehane merged 3 commits into
cypress-io:developfrom
akasakariko:issue-30869
Nov 6, 2026
Merged

jennifer-shehane merged 3 commits into
cypress-io:developfrom
akasakariko:issue-30869

Conversation

@akasakariko

@akasakariko akasakariko commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Additional details

When port is unset, Cypress can receive a randomly assigned port that browsers block, such as 10080, causing the runner to fail with ERR_UNSAFE_PORT

Cypress now releases a blocked randomly assigned port and retries, with a limit of 10 attempts and an error explaining when no permitted port could be found

Configured ports are checked during configuration validation before the file server or runner starts, using the same restricted port list as the retry logic

Runner bind failures release the file server, bind errors other than EADDRINUSE reject instead of hanging, and a failure to close a blocked listener is surfaced without retrying

Steps to test

  • Set port to 10080 in a project configuration and run cypress run or cypress open
  • Verify that a configuration error names the blocked port before the runner starts
  • Remove port from the configuration and verify that the runner loads normally
  • Run yarn workspace @packages/config test
  • Run yarn workspace @packages/errors test
  • Run yarn workspace @packages/server test-unit -- test/unit/server-base.spec.ts test/unit/file_server.spec.ts test/unit/open_project.spec.ts test/unit/project-base.spec.ts

Local validation on macOS arm64 with Node 24.22.1 and Yarn 1.22.22:

  • Config tests: 300 passed using a copy with identical source under a directory named cypress, as required by two existing directory-name assertions
  • Error tests: 206 passed
  • Server tests above: 199 passed and 4 existing tests skipped
  • Full workspace build and development V8 snapshot generation passed
  • Type checks passed for @packages/config, @packages/errors and @packages/server
  • Root and scoped lint passed with 0 errors and 28 warnings in unchanged server files
  • Binary changelog validation passed, including the entry for this PR

How has the user experience changed?

Cypress avoids randomly assigned ports that browsers block and reports an actionable configuration error for a blocked configured port

Runs using permitted ports behave as before

PR Tasks

  • Is there an associated issue with maintainer approval for PR submission?
  • Have tests been added/updated?
  • [na] Has a PR for user-facing changes been opened in the cypress-documentation repository?
  • [na] Have API changes been updated in the type definitions?

Comment thread packages/config/src/unsafe_ports.ts Resolved
Comment thread packages/server/lib/server-base.ts Resolved
Comment thread packages/server/lib/server-base.ts Resolved
Comment thread packages/server/lib/server-base.ts Resolved
Comment thread packages/server/lib/server-base.ts Resolved
@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@akasakariko

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in 399d3f8:

  • Added the missing 4190 and 6679 restricted ports and corrected the 993 comment
  • The port option now rejects browser blocked ports during configuration validation, so the error is reported before the file server starts
  • A blocked ephemeral port now has its own message, and cypress open routes the configured port error through errors.throwErr like PORT_IN_USE_SHORT
  • The file server is closed when the runner server fails to start, and a close error is surfaced instead of retried

Comment thread packages/server/lib/server-base.ts Resolved
Comment thread packages/server/lib/open_project.ts Resolved
akasakariko and others added 3 commits November 6, 2026 09:55
Discard a randomly assigned port that browsers refuse to load and report an actionable error when a blocked port is configured

Reject a bind failure other than EADDRINUSE so the run cannot hang before it starts

Fixes cypress-io#30869
Add the missing 4190 and 6679 restricted ports and correct the 993 comment

Reject a configured port that browsers block during configuration validation so it is reported before the file server starts

Use a separate message when every randomly assigned port was blocked

Close the file server when the runner server fails to start and surface close errors instead of retrying

Fixes cypress-io#30869
Rely on configuration validation for configured ports and keep the runner error specific to exhausted ephemeral port retries

Remove the duplicate validation, helper, test and unused error variant, restore port-in-use handling and remove historical test commentary

Keep one current changelog entry after rebasing onto develop
@cypress

cypress Bot commented Nov 6, 2026

Copy link
Copy Markdown

cypress    Run #75275

Run Properties:  status check passed Passed #75275  •  git commit 7d5e3ad5fd: fix: simplify browser blocked port handling (#35262)
Project cypress
Branch Review pull/35262/head
Run status status check passed Passed #75275
Run duration 15m 28s
Commit git commit 7d5e3ad5fd: fix: simplify browser blocked port handling (#35262)
Committer akasakariko
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 14
Tests that did not run due to a developer annotating a test with .skip  Pending 1044
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 30164
View all changes introduced in this branch ↗︎
UI Coverage  67.12%
  Untested elements 24  
  Tested elements 49  
Accessibility  99%
  Failed rules  0 critical   3 serious   2 moderate   0 minor
  Failed elements 18  

@jennifer-shehane
jennifer-shehane merged commit 214545f into cypress-io:develop Nov 6, 2026
85 of 87 checks passed
@cypress-bot

cypress-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Released in 16.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v16.3.0, please open a new issue.

@cypress-bot cypress-bot Bot locked as resolved and limited conversation to collaborators Nov 10, 2026

This branch was previously deployed

1 inactive deployment
fork-pr-review — 7d5e3ad5 Deployed Nov 6, 2026 by akasakariko via Semantic Pull Request #59600
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random ERR_UNSAFE_PORT for address that starts with http://localhost:10080 after spec launched

3 participants