Skip to content

Fix stale packager connections on Android (re-land) - #60403

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
vonovak:codex/stale-packager-connection-reland
Dec 2, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
vonovak:codex/stale-packager-connection-reland

Conversation

@vonovak

@vonovak vonovak commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Re-lands #58971 (stale packager connections on Android), which #60318 reverted. Same connection fix, plus:

  • isValidHost uses Request.Builder.url(String), which OkHttp 3 and 4 both have. toHttpUrlOrNull exists only in OkHttp 4.
  • Tests use localhost, so they have no hardcoded IP addresses.

For the importer: DevServerHelperTest needs a dependency on the DeveloperSettings interface.

Changelog:

[ANDROID] [FIXED] - Close stale packager connections when the dev server changes

Test Plan:

  • CI
  • on-device

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at 39da5ccc3957.

ios: no capture

@vonovak
vonovak marked this pull request as ready for review November 30, 2026 18:18
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 30, 2026
DevServerHelper opened and closed the packager connection in separate
AsyncTasks on THREAD_POOL_EXECUTOR. A close could run before a pending
open, and repeated opens could create two clients. Changing the bundle
location from the dev menu also kept the old connection. In both cases,
the old dev server could still reload the app.

- Run openPackagerConnection and closePackagerConnection as tasks on one
  single-threaded executor. Tasks run in call order, off the UI thread,
  and only that thread uses packagerClient. The executor names its
  thread ReactPackagerConnection and stops it after 30 seconds without
  work.
- Remember the host of the open client. If an open finds a client for a
  different host, close it and connect to the new host.
- Check clientId on the caller's thread. A failed init() still crashes
  the app, as before; packagerClient stays null, so a later open can
  retry.
- Change Bundle Location: close the packager connection before the
  reload, as setBundleSource does. Trim the input, then reject a host
  that OkHttp cannot parse in the connection URL and show a toast.
  Before, an invalid host was saved without a check.
- ReconnectingWebSocket: change close state under the socket's monitor,
  so no message handler starts after closeQuietly() returns. Close a
  socket whose handshake finishes after closeQuietly() instead of
  reporting it as connected.
- Add DevServerHelperTest and ReconnectingWebSocketTest.

This re-lands react#58971, which was reverted in react#60318:

- Validate the host with Request.Builder.url(String), which OkHttp 3 and 4
  both have. HttpUrl.Companion.toHttpUrlOrNull exists only in OkHttp 4.
- Use localhost in test fixtures, so the tests have no hardcoded IP
  addresses.
- Drop DevSupportHttpClientTest. It mostly tested OkHttp's URL parser and
  needed a separate downstream test target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vonovak
vonovak force-pushed the codex/stale-packager-connection-reland branch from ecb6083 to 39da5cc Compare November 30, 2026 18:24
@meta-codesync

meta-codesync Bot commented Dec 1, 2026

Copy link
Copy Markdown

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D135356300.

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync
meta-codesync Bot merged commit 1df562c into react:main Dec 2, 2026
74 of 82 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @vonovak in 1df562c

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants