dotnet network_error ai_generated partial

Microsoft.AspNetCore.SignalR.HubException: Failed to negotiate with the server. The negotiation request timed out after 30 seconds.

ID: dotnet/signalr-negotiate-timeout

Also available as: JSON · Markdown · 中文
75%Fix Rate
82%Confidence
1Evidence
2023-11-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
6.0 active
7.0 active
8.0 active

Root Cause

SignalR client fails to complete the negotiation handshake within the default timeout, typically due to network latency, server overload, or firewall blocking the WebSocket upgrade.

generic

中文

SignalR 客户端未能在默认超时时间内完成协商握手,通常是由于网络延迟、服务器过载或防火墙阻止 WebSocket 升级。

Official Documentation

https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-8.0

Workarounds

  1. 80% success Increase the negotiation timeout on the client: in JavaScript, use 'const connection = new signalR.HubConnectionBuilder().withUrl('/hub').configureLogging(signalR.LogLevel.Information).build();' and set 'connection.serverTimeoutInMilliseconds = 60000;' before starting.
    Increase the negotiation timeout on the client: in JavaScript, use 'const connection = new signalR.HubConnectionBuilder().withUrl('/hub').configureLogging(signalR.LogLevel.Information).build();' and set 'connection.serverTimeoutInMilliseconds = 60000;' before starting.
  2. 75% success Optimize server-side negotiation by reducing the number of transports offered: in Program.cs, use 'app.MapHub<MyHub>("/hub", options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents; });' to skip slow transport negotiation.
    Optimize server-side negotiation by reducing the number of transports offered: in Program.cs, use 'app.MapHub<MyHub>("/hub", options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents; });' to skip slow transport negotiation.

中文步骤

  1. Increase the negotiation timeout on the client: in JavaScript, use 'const connection = new signalR.HubConnectionBuilder().withUrl('/hub').configureLogging(signalR.LogLevel.Information).build();' and set 'connection.serverTimeoutInMilliseconds = 60000;' before starting.
  2. Optimize server-side negotiation by reducing the number of transports offered: in Program.cs, use 'app.MapHub<MyHub>("/hub", options => { options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents; });' to skip slow transport negotiation.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Increasing the client timeout alone may mask underlying network issues; the server must also handle long-running negotiations.

  2. 50% fail

    Disabling WebSocket transport forces fallback to long polling, which can degrade performance and still timeout if the server is overloaded.