Detach methods when disconnection confirmed.#66275
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a Blazor Server reconnection edge-case where CircuitManager.reconnect() re-attaches renderer interop methods but (when ConnectCircuit is rejected) fails to clean them up, causing a subsequent resume() path to throw "Interop methods are already registered for renderer 1".
Changes:
- Detach web renderer interop methods when
ConnectCircuitreturnsfalseduringCircuitManager.reconnect(). - Add Jest coverage to reproduce the reconnect-then-resume double-registration scenario and validate the detach behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts | Detaches renderer interop on ConnectCircuit rejection to avoid stale registration across reconnect/resume. |
| src/Components/Web.JS/test/WebRendererInteropMethods.test.ts | Adds regression tests covering the reconnect failure path and ensuring a new renderer can register interop methods after resume. |
There was a problem hiding this comment.
Maybe there could be a more fundamental fix for the broader workflow (that would avoid this in the first place) but I think this is a good low-risk fix for the problem that people run into in practice.
Let's merge it into P4 and after some time consider for servicing.
|
/backport to release/10.0 |
|
Started backporting to |
When a Blazor Server client loses connection,
DefaultReconnectionHandlercallsCircuitManager.reconnect(). IfConnectCircuitfails (circuit expired), it falls back toresume(), which creates a new RemoteRenderer on the server.That renderer's constructor calls
attachWebRendererInterop(1, newMethods)via JS interop. But reconnect() re-attached saved interop methods and didn't clean them up when ConnectCircuit returned false — causing:The fix:
CircuitManager.reconnect()callsdetachWebRendererInteropwhenConnectCircuitreturns false.The test exercises reconnect() on a
CircuitManagerwith mocked internals to verify the fix, then confirms the server can register new interop methods.Fixes #64738.