Skip to content

[DevServer] Investigate how to use localhost first on desktop #17757

Description

@jeromelaban

What would you like to be added

Investigate how connect to localhost first to avoid many websocket errors on multi-homed devices.

Why is this needed

Connecting to localhost first would work for same-machine, then if it fails (e.g. remote development on a RPi) fallback to the rest of the known addresses.

We could also somehow prioritize addresses based on the "last known working", where the devserver could store the binding address of the last successful connection, then prioritize this one in a subsequent build. This would reduce the number of connection errors in Wasm and other targets and make "first-chance" debugging less annoying.

For which platform

No response

Anything else we need to know?

No response

Activity

  1. added
    kind/enhancement
    triage/untriaged
    difficulty/tbd
    area/hot-reload
    and removed
    triage/untriaged
    on Jul 29, 2024
  2. dr1rrb commented on Aug 6, 2024

    @dr1rrb
    Member

    #17781 will make sure to prioritize the last known host. While it's not about connecting to localhost first, it will ensure to not cause lot of exception at startup.

  3. added theissue type on Jul 21, 2025
  4. github-actions commented on May 6, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  5. added
    stale
    on May 6, 2026
  6. removed
    stale
    on May 6, 2026
  7. MartinZikmund commented on May 6, 2026

    @MartinZikmund
    Member

    @carldebilly @dr1rrb still relevant?

  8. carldebilly commented on May 6, 2026

    @carldebilly
    Member

    To my knowledge, it has not been done yet. I'll check it.

  9. self-assigned this
    on May 6, 2026
  10. carldebilly commented on May 6, 2026

    @carldebilly
    Member

    Status update after re-reading the code today.

    What's already in place

    Two pieces have landed since the issue was opened, both in src/Uno.UI.RemoteControl/RemoteControlClient.cs:

    1. Last-known-good endpoint priority (PR fix(devSrv): Improve dev-server reliability #17781). StartConnection reads the last endpoint that succeeded from ApplicationData.Current.LocalSettings and gives it delay = 0; all other candidates are delayed by 3000 ms. This significantly reduces the first-chance exception noise on subsequent runs (lines 390-415).
    2. 127.0.0.1 prepended on desktop/WASM (lines 270-289). For Browser/Windows/Linux/macOS, IPAddress.Loopback.ToString() is added at the head of the address list when not already present. Mobile is excluded.

    What's still missing (the actual ask)

    • IPv6 loopback ([::1]) is never tried. Only IPv4 is prepended. On dual-stack or IPv6-leaning environments, this leaves cases uncovered.
    • Mobile is excluded too aggressively. Several mobile sub-cases would benefit from a same-machine loopback candidate:
      • iOS Simulator → 127.0.0.1 / [::1] reach the host (shared network stack).
      • Android Emulator (AVD) → 10.0.2.2 is the canonical alias for the host machine; 127.0.0.1 also works when adb reverse is set up.
      • Real devices → no change; the IDE-injected LAN address is the right answer.
    • Loopback dedup is string-exact. "localhost", "127.0.0.1", "[::1]" are treated as unrelated entries, so duplicates can creep in if the IDE injects one of them, and the preferred matching at line 398 does not recognize them as equivalent (a saved 127.0.0.1 won't boost a fresh localhost injection, etc.).

    Proposed direction

    Use IP literals (not localhost) to avoid DNS resolution on the startup-critical path and to dodge ClientWebSocket.ConnectAsync's lack of Happy Eyeballs (passing a hostname picks one family only). Platform-specific candidate lists via #if (consistent with the rest of Uno.UI.RemoteControl):

    Target Loopback candidates prepended
    WASM, Skia desktop 127.0.0.1, [::1]
    iOS (Simulator only, runtime-detected) 127.0.0.1, [::1]
    Android (Emulator only, runtime-detected) 10.0.2.2, 127.0.0.1
    iOS / Android real devices none

    Plus a small loopback-equivalence helper so the preferred last-known-host matching treats the loopback group as one. The parallel Task.WhenAny race already in StartConnection makes adding multiple candidates effectively free.

    Picking this up — will follow with a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/hot-reloaddifficulty/tbdkind/enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions