Repository navigation
Revert "Fix stale packager connections on Android" - #60318
Conversation
This reverts commit 99a157b. Restore downstream Android build compatibility with OkHttp 3 while source compatibility and test/build integration fixes are validated together.
|
@vonovak we had to revert 99a157bbfd4accecc72c42b79ecf0eeb25452487, merged in #58971. See the reason in the summary |
|
@cipolleschi thanks for the info
do I need to do anything to bring the change into the core or will someone take this over in meta? |
@vonovak Could you resubmit the PR and ask your agent to make sure the code is source compatible with OkHTTP 3.x? We've added instructions in the AGENTS.md also about this |
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>
## 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 Differential Revision: D135356300 Pull Request resolved: #60403
Summary
Reverts 99a157bbfd4accecc72c42b79ecf0eeb25452487, merged in #58971 ("Fix stale packager connections on Android").
The original change addresses a real bug when switching between Metro servers, but it introduced failures in downstream Android builds:
okhttp3.HttpUrl.Companion.toHttpUrlOrNull, an API available in OkHttp 4 but absent from OkHttp 3.14.9. Consumers whose dependency graph selects OkHttp 3.14.9 fail to compile React Native. The regression suites use OkHttp 4.10.0, so passing those tests did not cover this compatibility requirement.DeveloperSettingsinterface dependency. Those were missing from the downstream test configuration. The deliberate loopback/emulator IP fixtures also triggerHardcodedIPAddressUselint without targeted suppressions. These failures block importing the change and cause cascading build/E2E failures.A compatibility follow-up was prepared in #60317, but the agreed approach is to revert the full change to restore build compatibility, then revisit it with the source compatibility and test/build integration fixes validated together. This revert supersedes that follow-up.
This restores the packager/WebSocket lifecycle and bundle-location behavior from before #58971. The original stale-connection bug can therefore recur until a revised fix lands; that fix should be validated with both OkHttp 3 and 4 consumers and the complete downstream build/test configuration.
Changelog
[ANDROID] [FIXED] - Revert the stale packager connection fix to restore Android build compatibility with OkHttp 3
Test Plan
git revert --no-commit 99a157bbfd4accecc72c42b79ecf0eeb25452487applied cleanly to upstream main at1f43abd0247a82284b31969312588035d4407e9d.git diff --cached --checkpassed.--do-not-remove-unused-imports --dry-run --set-exit-if-changed.Full Android builds, unit tests, and device UI testing were not run locally for this revert. The earlier local Gradle attempt for #60317 stopped before tests when codegen dependency installation hit a registry proxy HTTP 503. Fresh GitHub CI is required for the revert.