Skip to content

DevServer: server-side WebSocket keepalive/timeout on /rc to reap half-open connections #24206

Closed

Description

@dr1rrb

Follow-up from the investigation on #24151.

The server connection loop (RemoteControlServer.HandleConnectionAsync) only exits when ReceiveAsync returns null/throws. There is no server-side WebSocket keepalive (app.UseWebSockets() is configured without KeepAliveInterval). Keep-alive/ping messages exist in the protocol, but the server side does not use them to detect a dead peer.

Consequence: if an app dies without a clean TCP close (hard crash, network drop, or a client reconnect that abandons the old socket), the old /rc connection stays "open" server-side → its workspace + DebuggingSession (~500 MB) linger indefinitely, coexisting with the new connection's workspace. Measured: two concurrent connections = two workspaces (~1.35 GB), zero Disposing connection.

Proposal: enable server-side WebSocket keepalive with a timeout (or an application-level ping deadline using the existing KeepAlive messages), and dispose the connection scope (→ EndSession + workspace dispose) when a peer stops responding. This reaps orphaned workspaces with no active kill and no risk of a reconnect storm.

Activity

  1. added a commit that references this issue on Aug 28, 2026
    6f057b7
  2. added theissue type on Sep 11, 2026
  3. khaskoul commented on Sep 14, 2026

    @khaskoul

    Verified on Uno.WinUI.DevServer 6.8.0-dev.159 (Uno.Sdk 6.8.0-dev.39), Windows, net10.0-desktop. Partially
    fixed
    — the keepalive lands, the workspace reclaim does not.

    Fixed: RemoteControlServer.HandleConnectionAsync now bounds every receive with
    receiveCts.CancelAfter(keepAliveTimeout), where ResolveKeepAliveTimeout() = uno-devserver:keep-alive-timeout-ms
    if set, else KeepAliveMessage.Interval (30s) × 2.1 = 63 s.

    Tested against a real half-open socket (NtSuspendProcess on a connected app — TCP stays established, client stops
    pinging):

    • default: connection closed 63 s after the last ping (lifetime 94.6 s), then Disposing connection + Unloading assembly context UnoApp1
    • --uno-devserver:keep-alive-timeout-ms=15000: lifetime drops to 17–20 s

    Deadline is causal, config knob works, and the "zero Disposing connection" symptom is gone.

    Not fixed: the ticket also expects the scope disposal to give "EndSession + workspace dispose" and to "reap
    orphaned workspaces". EndSession happens; the workspace dispose doesn't. gcroot on a dump taken right after the
    reap (single app, single workspace):

    type instances rooted
    EditAndContinue.DebuggingSession 1 0 roots ✅
    MSBuild.MSBuildWorkspace 1 still rooted ❌
    ServerHotReloadProcessor 1 still rooted
    Uno.HotReload.HotReloadManager 1 still rooted

    Host RSS stayed at 565 MB. (RSS alone proves nothing here — the host runs workstation GC with HeapHardLimitPercent: 66, so nothing decommits on an idle machine; hence gcroot.)

    Two causes:

    1. ServerHotReloadProcessor.Dispose() cancels but never drops the reference — _workspace?.Ct.Cancel(); with no
      _workspace = null. Compare DisableHotReloadAsync (the fix(devserver): cap concurrent hot-reload workspaces, disable oldest without closing the socket #24240 cap path), which does null it, and whose workspaces I
      measured as genuinely unrooted.
    2. The disposed scope is still reachable, so it can't be collected:

    AssemblyLoadContext (held by Roslyn MEF DefaultAnalyzerService -> AnalyzerAssemblyLoader)
    -> Func<ALC, AssemblyName, Assembly> (Resolving handler, never unsubscribed)
    -> DefaultRemoteControlProcessorFactory
    -> ServiceProviderEngineScope (the "disposed" connection scope)
    -> RemoteControlServer -> ServerHotReloadProcessor -> HotReloadManager -> MSBuildWorkspace

  4. Jen-Uno commented on Sep 30, 2026

    @Jen-Uno
    Contributor

    QA: closing out without a manual pass. The fix in #24213 ships with automated tests (Given_KeepAliveTimeout.cs) that exercise the change.

    If you still see this behaviour on a build that includes that PR, please reopen or comment here.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions