question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't established SignalR connection as negotiate results in 404

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We have 2 applications, one SignalR Server and another SignalR client written in C#. The application works fine for most of our environments but in some cases it is seen that the C# client fails to establish a connection to the SignalR server. The error message that we get is: Response status code does not indicate success: 404. What’s more interesting is that for other users on the same machine the client is able to establish a connection with the server but for other users it is unable to do so. Here’s the stack trace for the client:

 at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.NegotiateAsync(Uri url, HttpClient httpClient, ILogger logger, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.GetNegotiationResponseAsync(Uri uri, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.SelectAndStartTransport(TransferFormat transferFormat, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsyncCore(TransferFormat transferFormat, CancellationToken cancellationToken)
   at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsync(TransferFormat transferFormat, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncCore(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncInner(CancellationToken cancellationToken)
   at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsync(CancellationToken cancellationToken)

If we try to skip the negotiate call to the SignalR server from the SignalR client then this results in the error with message: The server returned status code ‘404’ when status code ‘101’ was expected and with the following stack trace:

at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
 at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.StartAsync(Uri url, TransferFormat transferFormat, CancellationToken cancellationToken)
 at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartTransport(Uri connectUrl, HttpTransportType transportType, TransferFormat transferFormat, CancellationToken cancellationToken)
 at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.SelectAndStartTransport(TransferFormat transferFormat, CancellationToken cancellationToken)
 at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsyncCore(TransferFormat transferFormat, CancellationToken cancellationToken)
 at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()
 at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsync(TransferFormat transferFormat, CancellationToken cancellationToken)
 at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)\r\n at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
 at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncCore(CancellationToken cancellationToken)
 at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncInner(CancellationToken cancellationToken)
 at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()
 at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsync(CancellationToken cancellationToken)

Note: I tried to create a POST request to the negotiate endpoint using an HTTP client like Postman and this returns fine with various options for communication with status code 200.

Expected Behavior

The C# SignalR client must be able to establish a connection with SignalR server.

Steps To Reproduce

  • Create a simple ASP.NET Core app as a SignalR server.
  • Create a simple ASP.NET Core app as a SignalR client.

Exceptions (if any)

No response

.NET Version

3.1.0

Anything else?

OS: Windows Server 2016 Data Center Edition

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Mar 25, 2022

The fact that you’re getting a real response (404) implies that you’re hitting the server, so we can temporarily rule out proxies or firewalls. Additionally, if you still get 404’s when skipping negotiate, that implies you’re either not using multiple servers, or have sticky sessions enabled correctly.

The final reason I can think of that you would get a 404 is that you’re hitting the wrong endpoint. Collect Debug or Trace level logs on your server and see what is happening for the failed connections. https://docs.microsoft.com/aspnet/core/signalr/troubleshoot?view=aspnetcore-6.0#response-code-404

https://docs.microsoft.com/aspnet/core/signalr/diagnostics?view=aspnetcore-6.0#server-side-logging

0reactions
msftbot[bot]commented, Apr 4, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR Negotiate 404 - asp.net
Here is the code where "MyApp" is the virtual directory of my web application. var connection = $.hubConnection('/MyApp/signalr', { ...
Read more >
SingalR Angular Error 404 - Microsoft Q&A
: Status code '404' Either this is not a SignalR endpoint or there is a proxy blocking the connection. it prints the top...
Read more >
Resolved: SignalR Error: Failed To Complete Negotiation ...
Exact Error Message: “Error: Failed to complete negotiation with the server: Error: Not Found: Status code '404' Either this is not a SignalR...
Read more >
Signalr Negotiate
Can't established SignalR connection as negotiate results in 404. It gets to the negotiate line and it stops SignalR UserID without authentication.
Read more >
Build Real-time Applications with ASP.NET Core SignalR
ASP.NET SignalR automatically handles restarting the connection when a disconnection occurs. Reconnection behavior is often specific to each ...
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