Skip to content

Blazor Server .net 9 Websocket connection fails, Same site with .net 8 works fine #58932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
selaromdotnet opened this issue Nov 13, 2024 · 12 comments
Labels
area-blazor Includes: Blazor, Razor Components
Milestone

Comments

@selaromdotnet
Copy link

I'm encountering a strange issue and I'm not really sure how to approach it. I host my websites with smarterasp.net which added support for .net 9 with yesterday's release...

However, after upgrading and publishing my blazor server app from .net 8.0 to 9.0, it is failing to establish the websocket connection and not running as expected.

The only difference between these two sites is the .net version (and the associated nuget packages), so I can only think that it's a problem with the environment or a bug, and I'm not really sure how to confirm either...

I published the .net 8 site here: https://dev.mcallengaragesales.com which loads and connects and seems to run fine on Firefox, edge, chrome on both desktop and mobile.

I upgraded that same site to .net 9 and published it here: https://dev9.mcallengaragesales.com and on firefox desktop I get this error:

[2024-11-13T22:05:24.792Z] Information: Normalizing '_blazor' to 'https://dev9.mcallengaragesales.com/_blazor'. [blazor.web.js:1:47102](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:25.504Z] Information: WebSocket connected to wss://dev9.mcallengaragesales.com/_blazor?id=VYh6X3Cn47ojOab5M2uiXQ. [blazor.web.js:1:47102](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
The connection to wss://dev9.mcallengaragesales.com/_blazor?id=VYh6X3Cn47ojOab5M2uiXQ was interrupted while the page was loading. [blazor.web.js:1:80199](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:44.757Z] Information: (WebSockets transport) There was an error with the transport. [blazor.web.js:1:47102](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:44.758Z] Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 (no reason given).'. [blazor.web.js:1:47019](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:44.758Z] Error: Error: WebSocket closed with status code: 1006 (no reason given). [blazor.web.js:1:39473](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:44.758Z] Error: Error: Cannot send data if the connection is not in the 'Connected' State. [blazor.web.js:1:39473](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:44.758Z] Information: Normalizing '_blazor' to 'https://dev9.mcallengaragesales.com/_blazor'. [blazor.web.js:1:47102](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
Firefox can’t establish a connection to the server at wss://dev9.mcallengaragesales.com/_blazor?id=182Go0fRvtQfWVWgU8PcYw. [blazor.web.js:1:80199](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:45.486Z] Information: (WebSockets transport) There was an error with the transport. [blazor.web.js:1:47102](https://dev9.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:05:45.486Z] Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.

On chrome desktop I get a similar but slightly different error:

[2024-11-13T22:04:43.733Z] Information: Normalizing '_blazor' to 'https://dev9.mcallengaragesales.com/_blazor'.
blazor.web.js:1 WebSocket connection to 'wss://dev9.mcallengaragesales.com/_blazor?id=nXyCEXfix-zJi1n89EgOrg' failed: 
(anonymous) @ blazor.web.js:1Understand this errorAI
blazor.web.js:1 [2024-11-13T22:04:44.158Z] Information: (WebSockets transport) There was an error with the transport.
blazor.web.js:1 [2024-11-13T22:04:44.158Z] Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
log @ blazor.web.js:1Understand this errorAI
blazor.web.js:1 [2024-11-13T22:04:44.503Z] Warning: Failed to connect via WebSockets, using the Long Polling fallback transport. This may be due to a VPN or proxy blocking the connection. To troubleshoot this, visit https://aka.ms/blazor-server-using-fallback-long-polling.

On mobile, the .net 9 site simply shows the standard blazor error with reload message at the footer (I don't know how to see dev tools on android to get more detailed errors)...

As an attempt to eliminate any other variables, I created a brand new, clean, default blazor web site for .net 9 using server interactive in visual studio and published that here: http://test.mcallengaragesales.com

and in firefox on THAT site, I get this error:

[2024-11-13T22:09:59.631Z] Information: Normalizing '_blazor' to 'http://test.mcallengaragesales.com/_blazor'. [blazor.web.js:1:47102](http://test.mcallengaragesales.com/_framework/blazor.web.js)
Firefox can’t establish a connection to the server at ws://test.mcallengaragesales.com/_blazor?id=e_FiqjqOx95vihFDg7P8CA. [blazor.web.js:1:80199](http://test.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:09:59.984Z] Information: (WebSockets transport) There was an error with the transport. [blazor.web.js:1:47102](http://test.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:09:59.985Z] Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled. [blazor.web.js:1:47019](http://test.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:10:00.708Z] Warning: Failed to connect via WebSockets, using the Long Polling fallback transport. This may be due to a VPN or proxy blocking the connection. To troubleshoot this, visit https://aka.ms/blazor-server-using-fallback-long-polling. [blazor.web.js:1:39512](http://test.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:10:01.576Z] Error: There was an error applying batch 2. [blazor.web.js:1:39473](http://test.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:10:01.579Z] Error: There was an error applying batch 3. [blazor.web.js:1:39473](http://test.mcallengaragesales.com/_framework/blazor.web.js)
[2024-11-13T22:10:01.805Z] Error: System.AggregateException: One or more errors occurred. (TypeError: n.parentNode is null)

 ---> System.InvalidOperationException: TypeError: n.parentNode is null

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)

   --- End of inner exception stack trace --- [blazor.web.js:1:39473](http://test.mcallengaragesales.com/_framework/blazor.web.js)
XHRPOST
http://test.mcallengaragesales.com/_blazor?id=_pNXLGiS-NE3aR74tAFcdQ
[HTTP/1.1 404 Not Found 88ms]

[2024-11-13T22:10:01.948Z] Information: Connection disconnected. [blazor.web.js:1:47102](http://test.mcallengaragesales.com/_framework/blazor.web.js)

and this on edge:

[2024-11-13T22:11:15.038Z] Information: Normalizing '_blazor' to 'http://test.mcallengaragesales.com/_blazor'.
blazor.web.js:1 [2024-11-13T22:11:15.282Z] Information: WebSocket connected to ws://test.mcallengaragesales.com/_blazor?id=WlqbMNRCNy-5sQk5zMEA2A.
blazor.web.js:1  [2024-11-13T22:11:15.283Z] Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 (no reason given).'.
log @ blazor.web.js:1
_stopConnection @ blazor.web.js:1
features.reconnect.transport.onclose @ blazor.web.js:1
_close @ blazor.web.js:1
i.onclose @ blazor.web.js:1
blazor.web.js:1  [2024-11-13T22:11:15.283Z] Error: Error: WebSocket closed with status code: 1006 (no reason given).
log @ blazor.web.js:1
unhandledError @ blazor.web.js:1
startConnection @ blazor.web.js:1
await in startConnection
startCore @ blazor.web.js:1
start @ blazor.web.js:1
Qo @ blazor.web.js:1
await in Qo
Yo @ blazor.web.js:1
startCircutIfNotStarted @ blazor.web.js:1
resolveRendererIdForDescriptor @ blazor.web.js:1
determinePendingOperation @ blazor.web.js:1
refreshRootComponents @ blazor.web.js:1
(anonymous) @ blazor.web.js:1
setTimeout
rootComponentsMayRequireRefresh @ blazor.web.js:1
onDocumentUpdated @ blazor.web.js:1
Hi @ blazor.web.js:1
blazor.web.js:1  [2024-11-13T22:11:15.284Z] Error: Failed to start the circuit.


I am at a total loss for what to do. I want to publish the .net 9 site live today but I can't with this issue. I'm hoping it's an environment thing as opposed to a bug in my code (or .net) but at the same time I have no idea what to tell my host to try and remedy the issue...

Does anyone else get any different result than I am showing above? Any ideas what might be wrong here? anything more I can provide to give more insight?

many thanks for taking a look!

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Nov 13, 2024
@BrennanConroy
Copy link
Member

BrennanConroy commented Nov 13, 2024

Are you hosting with IIS OutOfProcess?

Also, try
MapRazorComponents<App>().AddServerSideComponents(o => o.DisableWebSocketCompression = true)

@selaromdotnet
Copy link
Author

oh yes thank you I forgot to mention that, both sites are outofprocess, that appears to be required for all .net core sites on smarterasp.

I'll try your suggestion and report back thanks!

@selaromdotnet
Copy link
Author

oh my that seems to have done it!!! I no longer get the error on any browser or mobile after disabling compression.

THANK YOU!!

I do wonder if this is an environment thing, as I'm sure I'd appreciate being able to use compression, but let me report this to the host, and see if I can find more docs on what's required and I'll report back any findings.

thanks again!!!

@BrennanConroy
Copy link
Member

OutOfProcess will not support compression, but we are fixing it to not fail the websocket connection.
#58931

@selaromdotnet
Copy link
Author

ah okay awesome thank you for sharing this additional insight, and the coming update to resolve it, you really made my day!

@javiercn
Copy link
Member

@BrennanConroy thanks for catching this.

@javiercn javiercn added this to the 9.0.1 milestone Nov 15, 2024
@techscx
Copy link

techscx commented Dec 11, 2024

When hosting behind iis via arr and forwarding to a server in a serverfarm, after upgrading to .net 9 the app doesn't work either caused by the new default compression. After disabling the compression, the app works again in .net 9.

@BrennanConroy
Copy link
Member

9.0.1 has been released and has a fix for this. To get the fixed bits you need to install the new hosting bundle, instructions and various options are described in https://learn.microsoft.com/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-9.0

The workaround:
MapRazorComponents<App>().AddServerSideComponents(o => o.DisableWebSocketCompression = true)
is no longer needed.

@dotnetappdev
Copy link

Its still causing an issue for me in blazor .net 9.0 hosting is shared hosting beyond my control @BrennanConroy the work around in lattest .net 9 doesnt seem to expose DisableWebSocketCompression

@sact1909
Copy link

9.0.1 has been released and has a fix for this. To get the fixed bits you need to install the new hosting bundle, instructions and various options are described in https://learn.microsoft.com/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-9.0

The workaround: MapRazorComponents<App>().AddServerSideComponents(o => o.DisableWebSocketCompression = true) is no longer needed.

I did install the new hosting bundle and I even set this

app.MapRazorComponents<App>() .AddInteractiveServerRenderMode(o=>o.DisableWebSocketCompression = true);

and still happen the same to me

Image

and this is new app created from Visual Studio templates doesn't have anything else than what comes with the template

@Richard-Dufour
Copy link

Are you hosting with IIS OutOfProcess?

Also, try MapRazorComponents<App>().AddServerSideComponents(o => o.DisableWebSocketCompression = true)

Thank you @BrennanConroy, in my case, what fixed it was:

app.MapRazorComponents<ChattelWeb.Components.App>()
.AddInteractiveServerRenderMode(o => o.DisableWebSocketCompression = true);

@dotnetappdev
Copy link

dotnetappdev commented Mar 21, 2025 via email

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
Projects
None yet
Development

No branches or pull requests

7 participants