Skip to content

Detach methods when disconnection confirmed.#66275

Merged
ilonatommy merged 2 commits intodotnet:mainfrom
ilonatommy:fix-64738
Apr 17, 2026
Merged

Detach methods when disconnection confirmed.#66275
ilonatommy merged 2 commits intodotnet:mainfrom
ilonatommy:fix-64738

Conversation

@ilonatommy
Copy link
Copy Markdown
Member

When a Blazor Server client loses connection, DefaultReconnectionHandler calls CircuitManager.reconnect(). If ConnectCircuit fails (circuit expired), it falls back to resume(), 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:

"Interop methods are already registered for renderer 1"

The fix: CircuitManager.reconnect() calls detachWebRendererInterop when ConnectCircuit returns false.

The test exercises reconnect() on a CircuitManager with mocked internals to verify the fix, then confirms the server can register new interop methods.

Fixes #64738.

@ilonatommy ilonatommy requested a review from javiercn April 11, 2026 07:55
@ilonatommy ilonatommy self-assigned this Apr 11, 2026
@ilonatommy ilonatommy requested a review from a team as a code owner April 11, 2026 07:55
@ilonatommy ilonatommy added the feature-circuit-lifecycle Issues to do with blazor server lifecycle events label Apr 11, 2026
Copilot AI review requested due to automatic review settings April 11, 2026 07:55
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Apr 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ConnectCircuit returns false during CircuitManager.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.

Comment thread src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts
Comment thread src/Components/Web.JS/test/WebRendererInteropMethods.test.ts Outdated
@ilonatommy ilonatommy requested a review from oroztocil April 13, 2026 09:40
Copy link
Copy Markdown
Member

@oroztocil oroztocil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ilonatommy ilonatommy added this to the 11.0-preview4 milestone Apr 15, 2026
@ilonatommy ilonatommy merged commit e4c0496 into dotnet:main Apr 17, 2026
25 checks passed
@ilonatommy
Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

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

Labels

area-blazor Includes: Blazor, Razor Components feature-circuit-lifecycle Issues to do with blazor server lifecycle events

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor throws JSException message 'Interop methods are already registered for renderer 1' in unobserved task

4 participants