SignalR WebSockets - Error: There was an error with the transport.

See original GitHub issue

Describe the bug

Hey, I got a problem with WebSockets transport type. Since that, we are using LongPooling for now and it is working okayish. That thing is that if I want to connect to the hub with external application (node/js in browser) I get this error:

Error: Failed to start the connection: Error: There was an error with the transport.

It might be the thing that my server does not support WebSockets transport type, but since we are working on a bash systems I haven’t found solution yet.

This is the list what I thought of that might cause the issue (some things may be missing):

  • client/server package versions
  • ssl connections
  • CORS (well not in a nodejs console app, but in browser)
  • endpoints.MapHub<>("...", o => o.Transports = HttpTransportType.WebSockets); - no change
  • app.UseWebSockets() manually - no change
  • doesn’t matter if it’s executed inside docker container or at localhost
  • actually had to use skipNegotiations: true since I get 404
  • @aspnet/signalr and @microsoft/signalr differences

To Reproduce

  1. dotnet new webapi
  2. Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
     services.AddControllers();
     services.AddSignalR();
}

public void Configure(IApplicationBuilder app)
{
     app.UseRouting();
     app.UseEndpoints(endpoints =>
     {
            endpoints.MapControllers();
            endpoints.MapHub<ChatHub>("/hub/chat");
     });
}
  1. ChatHub.cs
public class ChatHub : Hub
{
}
  1. .csproj should look like this:
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>YOUR_APP_NAME</RootNamespace>
  </PropertyGroup>
  
</Project>
  1. Client (I used nodejs) index.js
const signalR = require("@microsoft/signalr");

let connection = new signalR.HubConnectionBuilder()
    .withUrl("http://localhost:5001/hubs/chat", { transport: signalR.HttpTransportType.WebSockets })
    .configureLogging(signalR.LogLevel.Debug)
    .build();

connection.start()
    .then(() => console.log("Connection started"))
    .catch(e => console.log(e));

package.json

{
  "name": "signalr-web-client",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@microsoft/signalr": "^3.1.3"
  }
}
  1. dotnet run
  2. node index.js

Further technical details

  • dotnet and OS
$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.102
 Commit:    573d158fea

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.1.102/

Host (useful for support):
  Version: 3.1.2
  Commit:  916b5cba26

.NET Core SDKs installed:
  3.0.100 [/usr/local/share/dotnet/sdk]
  3.1.102 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
  • node and npm
$ node -v
v12.13.0

$ npm -v
6.12.0
  • IDE
JetBrains Rider 2019.2.4
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mazxaxzcommented, May 6, 2020

@BrennanConroy ok, so actually there is no need to provide any logs. It started to work after PC reset (who would have known 😄), but the thing that messed up our production on k8s was the [Authorize] attribute causing Transport Error.

I’m gonna investigate that further and hopefully provide feedback in the future. You can close the issue, thanks for “helping” 😄

1reaction
mazxaxzcommented, May 5, 2020

@BrennanConroy ye, that was a typo, endpoint is the same. I’m gonna provide you the logs tomorrow, if thats ok 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core SignalR connection troubleshooting
This error is usually caused by a client using only the WebSockets transport but the WebSocket protocol isn't enabled on the server. Response ......
Read more >
How to fix " Error: Failed to start the transport 'WebSockets ...
I keep getting Failed to start the transport 'WebSockets': null when connecting to server. I'm implementing a simple chat in reactnative mobile ...
Read more >
SignalR: Losing connection after refreshing : r/dotnet
Net core/React app where I'm trying to implement SignalR. ... Information: (WebSockets transport) There was an error with the transport.
Read more >
Using signalR with nopcommerce 4.2
js:3082 [2020-02-05T09:13:12.921Z] Error: Failed to start the transport 'WebSockets': Error: There was an error with the transport. ConsoleLogger.log @ signalr.
Read more >
Network Load Balancer stickiness seems to fail sometimes
Sometimes, however, something strange happens: the negotiation fails (error in WebSocket transport), then the client tries again with another transport (SSE).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found