Skip to content

fix: recognize occupied ports returning HTTP errors - #2871

Open
curforever wants to merge 1 commit into
react-native-community:mainfrom
curforever:fix/http-error-packager-port
Open

curforever wants to merge 1 commit into
react-native-community:mainfrom
curforever:fix/http-error-packager-port

Conversation

@curforever

Copy link
Copy Markdown

Summary

When a process listening on the requested Metro port returns HTTP 400/404/500 for /status, the shared fetch helper throws CLIError. isPackagerRunning currently converts that response to not_running, so findDevServerPort skips the occupied-port flow and can try to start Metro on the same port.

Recognize the existing HTTP CLIError as unrecognized. Connection failures retain their existing behavior, and the public return type is unchanged. Add regression coverage with actual local HTTP servers and the port-selection caller.

Refs #2852; this addresses the HTTP-error classification case, not all errors discussed in that issue.

Test Plan

  • Windows / Node 22.12.0 / Yarn 1.22.22 / frozen lockfile: the identical 10-test file has 6 failures and 4 passes on the unchanged source, then 10 passes with the fix. Covers HTTP 400/404/500, port selection, ordinary HTTP 200, Metro status/root reuse, and connection refusal. yarn jest --selectProjects unit --runInBand packages/cli-tools/src/__tests__/isPackagerRunning.test.ts.
  • TypeScript and all 13 package JS builds pass. On Windows the upstream absolute backslash fast-glob build pattern matched no files; a process-local forward-slash adapter was used without changing the upstream build scripts.
  • Full yarn lint: 0 errors, 2 existing warnings. The workspace path contains #, so lint ran through a temporary ASCII alias with equivalent workspace junction targets. All targets and the alias were restored; no rules disabled.
  • Full packages unit/coverage run: 305 passed, 29 failed, 1 todo. Unchanged-source comparison: 300 passed, 34 failed, 1 todo (including the 6 new regressions). 28 existing failures match; the additional copyFiles case was independently reproduced with unchanged source on the fourth isolated run. The full Windows suite is not green.
  • Created an actual React Native 0.85.0 project from the published community template, using file: dependencies/resolutions to the local CLI build. On Node 22.13.0, verified CLI config, identical installed detection-module bytes, and 6 real local-HTTP scenarios with the actual built tools and injected prompt answers: error responses use another port when accepted and do not start Metro when declined; normal responses and closed ports retain their behavior. Metro responses were synthetic protocol responses; no real Metro/native Android/iOS build or full Linux/macOS e2e matrix was run locally.

Investigation, implementation and tests were AI-assisted. The validation steps above were executed locally; no manual maintainer review is claimed.

Checklist

  • Documentation is up to date (the existing status contract is preserved).
  • Follows the commit message convention described in CONTRIBUTING.md.
  • For functional changes, the test plan linked these CLI changes into a local React Native project using local package dependencies.

@curforever
curforever requested a review from thymikee as a code owner October 9, 2026 00:50
@github-actions github-actions Bot added the bugfix label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant