Skip to content

Fix stale inspector connections on Android - #59012

Open
vonovak wants to merge 2 commits into
react:mainfrom
vonovak:stale-inspector-connection
Open

vonovak wants to merge 2 commits into
react:mainfrom
vonovak:stale-inspector-connection

Conversation

@vonovak

@vonovak vonovak commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Same mechanics as #58971 (reverted in #60318)

Summary:

On Android, after an app switches to another Metro server, the debugger stays attached through the old one. The inspector connection lives across reloads, and DevServerHelper.openInspectorConnection did nothing when a connection already existed, so it never moved to the new host. Open and close also ran in separate AsyncTasks, with the same ordering race that #58971 fixes for the packager connection.

Changes:

  • Open and close the inspector connection on the same single-threaded executor as the packager connection. An open for a new host replaces the old connection.
  • inspectorPackagerConnection is volatile, because disableDebugger() reads it from other threads.
  • DevServerHelper no longer uses AsyncTask, so the import, the related comments and @SuppressLint("StaticFieldLeak") are gone. Lint reports no StaticFieldLeak issue without it.
  • Tests use a small factory field to replace the native CxxInspectorPackagerConnection, which can't run under Robolectric.

Possible follow-up: Change Bundle Location could also close the inspector connection before reloading, as it does for the packager connection, to cover a reload whose bundle fails to load.

Changelog:

[ANDROID] [FIXED] - Fix the debugger staying connected through the previous Metro server after switching to another one

Test Plan:

New tests in DevServerHelperTest pass, and so do the existing related tests.

On an emulator running RNTester with Metro on ports 8082 and 8083, I switched from 8082 to 8083 with Change Bundle Location. Before this change, Metro 8082 still listed the app in /json/list minutes later and 8083 listed nothing. With this change, 8083 lists the app and 8082 drops it within seconds.

🤖 Generated with Claude Code

@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 Oct 12, 2026
@vonovak
vonovak marked this pull request as ready for review October 12, 2026 22:02
@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 Oct 12, 2026
@vonovak
vonovak force-pushed the stale-inspector-connection branch from ffb94ec to 612cbcb Compare November 25, 2026 19:08
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at 7a9482e23045.

ios: no capture

@cortinico

Copy link
Copy Markdown
Contributor

@vonovak can you rebase and fix conflicts?

@vonovak

vonovak commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@vonovak can you rebase and fix conflicts?

thanks for reaching out, the PR requires #58971 first, which was reverted. waiting to see what's the next step there.

DevServerHelper opened and closed the inspector connection in separate
AsyncTasks, and the connection lives across reloads. After the dev
server host changed, the next open saw an existing connection and did
nothing, so the debugger stayed attached through the old Metro server.

- Run openInspectorConnection and closeInspectorConnection on the same
  single-threaded executor as the packager connection.
- Remember the host of the open inspector connection. If an open finds a
  connection for a different host, close it and connect to the new host.
- Make inspectorPackagerConnection volatile, because disableDebugger()
  reads it from other threads.
- DevServerHelper no longer uses AsyncTask: remove the import, the
  related comments, and @SuppressLint("StaticFieldLeak"). Lint reports
  no StaticFieldLeak issue without it.
- Add inspector tests to DevServerHelperTest, with a test factory that
  avoids the native connection class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vonovak
vonovak force-pushed the stale-inspector-connection branch from 612cbcb to 0f8d808 Compare December 2, 2026 13:05
@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 Dec 2, 2026
The re-land of the stale packager connection fix changed the test setup
host to localhost:8083. Match it in the inspector host-change test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. 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.

2 participants