dotnet
network_error
ai_generated
partial
Microsoft.AspNetCore.SignalR.HubException: 与服务器协商失败。协商请求在 30 秒后超时。
Microsoft.AspNetCore.SignalR.HubException: Failed to negotiate with the server. The negotiation request timed out after 30 seconds.
ID: dotnet/signalr-negotiate-timeout
75%修复率
82%置信度
1证据数
2023-11-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 6.0 | active | — | — | — |
| 7.0 | active | — | — | — |
| 8.0 | active | — | — | — |
根因分析
SignalR 客户端未能在默认超时时间内完成协商握手,通常是由于网络延迟、服务器过载或防火墙阻止 WebSocket 升级。
English
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.
官方文档
https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-8.0解决方案
-
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. -
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.
无效尝试
常见但无效的做法:
-
60% 失败
Increasing the client timeout alone may mask underlying network issues; the server must also handle long-running negotiations.
-
50% 失败
Disabling WebSocket transport forces fallback to long polling, which can degrade performance and still timeout if the server is overloaded.