SignalR client receives Information: Connection disconnected from hub - signalr

I created a signalR JavaScript client that needs to communicate with a hosted signalR server (from Playfab). I successfully created the signalR client and connected it with the server, but the problem that I'm facing is that the connection doesn't stay open more than 30 seconds even though I subscribe to events.
Here are the messages between the client and server. After one ping, the server sends a close message.
Messages between client and server
How can I prevent this from happening?
Here is how the connection is created
connection = new signalR.HubConnectionBuilder()
.withUrl(`url`, {
withCredentials: false,
httpClient: new SignalRClient(),
headers: {
'X-EntityToken': entity.EntityToken,
},
})
.build()
await connection.start()

Related

SignalR removes connection ID's from server

when I wrote server for game I got problem:
SignalR hub (with MessagePack) removes connection ID and then disconnects client.
Any Timeout options (in .AddSignalR) & Nginx headers doesn't help.

SignalR WebSockets work locally but not on server

I'm trying to get Web Sockets working as the protocol with an ASP.NET 4.8 Framework app that uses SignalR 2.4.2. It works fine with Visual Studio 2019 on localhost, running Windows 10 Pro. It fails on a Windows 2016 server (not Azure) with this error in Chrome 85:
signalr?v=igzza46L1gfiUBzl96WDUmuI9_CUHV_qqd0Kd-fDr8A1:1 WebSocket connection to 'wss://someServer.org/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=...&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=0' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
and
No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.
at Object.error (signalr?vv=...:1)
at g (signalr?vv=...:1)
at v (signalr?vv=...:1)
at h.transportFailed (signalr?vv=...:1)
at signalr?vv=...:1
at WebSocket.e.socket.e.socket.onclose (signalr?vv=...:1)
Opening this URL on the server https://myserver.org/signalr/negotiate to get the SignalR details produces the following:
Url "/signalr"
ConnectionToken "..."
ConnectionId "..."
KeepAliveTimeout 20
DisconnectTimeout 30
ConnectionTimeout 110
TryWebSockets true
ProtocolVersion "1.2"
TransportConnectTimeout 5
LongPollDelay 0
Here's the chain of console responses in Firefox for the failed call:
SignalR: Client subscribed to hub 'myhub'.
SignalR: Negotiating with '/signalr/negotiate?clientProtocol=2.1&connectionToken=...&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D'.
SignalR: webSockets transport starting.
SignalR: Connecting to websocket endpoint 'wss://myServer.org/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=...%3D%3D&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=8'
Firefox can’t establish a connection to the server at wss://myServer.org/signalr/connect?transport=webSockets&clientProtocol=2.1&connectionToken=...&connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&tid=8.
SignalR: Websocket closed.
SignalR: Closing the Websocket.
SignalR: webSockets transport failed to connect. Attempting to fall back.
SignalR: No fallback transports were selected.
SignalR: Stopping connection.
SignalR: Fired ajax abort async = true.
WebSockets has been installed on the server using these instructions:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/websocket#windows-server-2012-or-windows-server-2012-r2
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/websocket#how-to-configure-websocket
On the client, it's using the following:
$.connection.hub.logging = true;
$.connection.hub.start({ transport: ['webSockets'] })
.done(function () {
// ...
}).fail(e => {
console.log(e);
});;
In addition, BrowserLink is disabled in Visual Studio, as that's been mentioned as a possible cause of issues.
Additional articles researched:
https://stackoverflow.com/a/37531108/177416
https://github.com/SignalR/SignalR/issues/3148
Some suggested removing the Application_PreSendRequestHeaders from Global.asax.cs but this didn't change anything on the server.
I'm aware that SignalR supports other protocols but I'm trying to get Web Sockets working.
Thanks.
Update: The web sockets protocol also works on the localhost of the server itself, logging in via RDP and using a browser to open the page.
This was a tough nut to crack. Working with the system admins, we discovered it was caused by the load balance/proxy level, which sits in front of all our traffic. By default, it didn't support web sockets. Once web sockets were enabled, SignalR was happy.

gRPC Server Deployed in Container Cannot Establish SSL Connection

I am trying to deploy a simple grpc server written in asp.net core. The Kestrel settings are
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(c =>
{
c.Listen(IPAddress.Any, 8001);
c.ConfigureHttpsDefaults(https =>
{
https.ServerCertificate = new X509Certificate2("MyDemo.gRPC.pfx", "Pa55word");
});
})
.UseStartup<Startup>();
});
I have created a docker image and deployed it to an Azure Container Instance, and exposed port 8001. When I use an insecure channel to call the server from a client, I get a successful response, i.e
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
using var channel = GrpcChannel.ForAddress("http://01.02.3.04:8001");
gets the server to respond. However, when I try to use a secure channel and use https, I get the exception
Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. IOException: The handshake failed due to an unexpected packet format.
I presume that it is something to do with my Kestrel settings, can anyone see my problem?

Websocket hosted in ASPNET Core RC2, IIS "WebSocket connection to 'wss://xxx' failed: Error during WebSocket handshake: Unexpected response code: 302

I have a web socket server hosted in ASPNET Core RC2.
It works fine on my local dev box, when running on just kestrel, and also when kestrel is hosted in IIS.
When Google Chrome is used to connect to the websocket server, it works OK on local box, and on remote box:
JavaScript:
new WebSocket("wss://myServer:8087")
However when the JavaScript is connecting to the same server, hosted on our build machine (OS: Server 2008 R2) the client gets this 302 (redirect) error:
WebSocket connection to 'wss://myBuildServer:8087/' failed: Error during
WebSocket handshake: Unexpected response code: 302
note: when the JavaScript is running on Chrome on the server itself, the error is different:
WebSocket connection to 'wss://xxx:8087/' failed: WebSocket opening handshake was canceled
C# source that adds web sockets (Microsoft.AspNetCore.WebSockets.Server 0.1.0-rc2-final):
private void ConfigureWebSockets(IApplicationBuilder app)
{
DPT2.Web.Utils.Logger.Log("ConfigureWebSockets()");
_socketHandler = new Sockets.WebSocketHandler(_nodeServices);
app.UseWebSockets(new WebSocketOptions{
//try to fix 302 redirect on build m/c:
ReplaceFeature = true,
//TODO tune via these params:
KeepAliveInterval = TimeSpan.FromMinutes(2),
ReceiveBufferSize = 4 * 1024
});
app.Use(async (http, next) =>
{
if (http.WebSockets.IsWebSocketRequest)
{
var webSocket = await http.WebSockets.AcceptWebSocketAsync();
if (webSocket != null && webSocket.State == WebSocketState.Open)
{
await _socketHandler.Handle(webSocket);
}
}
else
{
// Nothing to do here, pass downstream.
await next();
}
});
}
It looks like the request is being 'corrupted' somehow, and this C# line does not recognise it as a web socket request, and so passes it on to MVC:
if (http.WebSockets.IsWebSocketRequest)
versions:
Server OS: Windows 2008 R2
IIS 6.1 build 7601 - SP1
IIS Manager 7.5.7600.16385
installed the ASPNET Core hosting: DotNetCore.1.0.0.RC2-WindowsHosting.exe
I've tried a few workarounds:
using http for the site, and ws:// for the web socket URL
using https for the site, and wss:// for the web socket URL
adding the ReplaceFeature option to the websocket server
Has anyone else seen a similar issue ?
I think its to do with IIS acting as a reverse proxy for kestrel, and perhaps on that particular machine, the proxying is messing up the web socket request ...
It could be a configuration issue on the server ...
Sean

Does the communication channel breaks in between client and server if we introduce a load balancer in SignalR?

I am new to SignalR and I have a question on SignalR communication when we introduce a load balancer.
Lets assume we want to execute a void method on server side which receives some data as a parameter from client. Server takes that data and processes further. Lets say after processing for a while, it identifies that it has to send the notification back to client.
Case 1(Between client and server): Client calls void method on server side(Hub) by passing some data. Connection gets disconnected. Server processes the client data further. When it identifies that it has to push the notification back to client, it recreates the connection and pushes back the data to client.
Case 2(Between client and server with load balancer in between): How does the above scenario(Case 1) work here?. When server sends the push notification back to load balancer after processing client data, how does it know to which client it has to send the notification back?
You should read the scaleout docs. Short version: messages get sent to all servers, so if the client reconnects (it's not the server that establishes the connection!) before the connection times out , it will get the message.
Quote from the docs:
The cursor mechanism works even if a client is routed to a different
server on reconnect. The backplane is aware of all the servers, and it
doesn’t matter which server a client connects to.

Resources