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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 50% 失败

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