Blazor Server circuit retention vs. client reconnection timeout for flaky networks
0 reputation · 15 Apr 2023, 22:53 UTC
0 reputation · 15 Apr 2023, 22:53 UTC
I'm designing a Blazor Server app (assume .NET 8) where users on unstable mobile connections intermittently lose the SignalR circuit. The documented knobs are server-side circuit retention (DisconnectedCircuitRetentionPeriod / DisconnectedCircuitMaxRetained) and the client-side reconnection behavior configured via Blazor.start({ reconnectionOptions }) or the default reconnection UI.
A longer retention period preserves component state so users resume seamlessly after brief drops, but retained circuits consume server memory per disconnected user, which matters at scale. Conversely, aggressive client reconnection attempts with short retention free server resources quickly but force users through full circuit re-creation and state loss more often.
It's unclear to me how these two settings interact in practice: whether the client gives up before the server retention window matters at all, and whether retained-circuit memory pressure is significant enough to justify shortening retention on a memory-constrained host.
DisconnectedCircuitRetentionPeriod?DisconnectedCircuitMaxRetained?32775 reputation · 16 Apr 2023, 01:00 UTC
Likely explanation: the client‑side reconnection window and the server’s DisconnectedCircuitRetentionPeriod act as two independent gates. If the client’s timeout exceeds the server retention window, the circuit is already gone, and reconnection attempts become a no‑op that only consumes SignalR thread budget.
Confirmed fact: the Blazor framework does not expose a per‑circuit memory counter; memory usage scales with component tree depth, injected services, and any active timers or threads held in the circuit.
DisconnectedCircuitRetentionPeriod on the server (e.g., 30 seconds) and record the initial process memory.Blazor.start({ reconnectionOptions: { timeout: 25000 } }) so the timeout is a few seconds under the server period, preventing wasted reconnection after circuit discard.Microsoft.AspNetCore.Blazor.Server.Circuit and capture CircuitCreated, CircuitDisconnected, and CircuitDisposed events; use the logs to correlate elapsed time with memory snapshots.To finalize the DisconnectedCircuitMaxRetained value and reconnection timeout, I need one diagnostic detail: approximately how many concurrent disconnected circuits your app typically holds in production, and whether any components hold transient timers or scoped services that inflate per‑circuit memory.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.