gpt4 book ai didi

azure - Azure Web App 重新启动后 SignalR 重新连接

转载 作者:行者123 更新时间:2023-12-02 06:49:00 24 4
gpt4 key购买 nike

重新启动托管我的 SignalR Hub 的 Azure Web 应用程序后,我遇到了奇怪的重新连接行为。当我重新启动时,即使应用程序在小于 DisconnectTimeout(测试时间为 2 分钟)内重新启动,客户端也不会重新连接。

我做错了什么吗?

中心代码

public class PingHub : Hub
{
public void Hello()
{
Clients.All.hello();
}

public override Task OnReconnected()
{
Trace.WriteLine("Reconnect");
return base.OnReconnected();
}

public override Task OnConnected()
{
Trace.WriteLine("Connect");
return base.OnConnected();
}

}

客户端代码

var hubConnection = new HubConnection("http://url/");


hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;

IHubProxy hubProxy = hubConnection.CreateHubProxy("PingHub");

hubProxy.On("hello", () => Console.WriteLine($"Hello {DateTime.Now.ToString()}"));

hubConnection.Reconnected += () =>
{
Console.WriteLine("Reconnected");
};

hubConnection.Start().Wait();

客户端跟踪日志

16:55:48.3999367 - null - ChangeState(Disconnected, Connecting)
16:55:48.8459354 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: GET http://gf-test-signalr.azurewebsites.net/signalr/connect?clientProtocol=1.4&transport=serverSentEvents&connectionData=[{"Name":"PingHub"}]&connectionToken=9Vs1ACQjDX%2BQmrcJ2XnoLCCJN%2FDtlJd%2BM0r5o8QvORX50ydXDkrAzeeVUgVIzNc3d7JcDvJ49KmxI3oVPQ%2Bt8IUMJe8HGFAJDasufD%2FFwxEr2l23l40q2dlKVADnFJA5
16:55:48.9604385 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: OnMessage(Data: initialized)
16:55:48.9609355 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: OnMessage(Data: {"C":"d-B53A1D13-E,0|F,0|G,1","S":1,"M":[]})
16:55:49.1059354 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - ChangeState(Connecting, Connected)
16:55:53.0300013 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: OnMessage(Data: {})
16:56:03.0655798 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: OnMessage(Data: {})
16:56:13.0791344 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: OnMessage(Data: {})
16:56:23.0965041 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: OnMessage(Data: {})
16:56:26.7919383 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - ChangeState(Connected, Reconnecting)
16:56:26.7939373 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: GET http://gf-test-signalr.azurewebsites.net/signalr/reconnect?clientProtocol=1.4&transport=serverSentEvents&connectionData=[{"Name":"PingHub"}]&connectionToken=9Vs1ACQjDX%2BQmrcJ2XnoLCCJN%2FDtlJd%2BM0r5o8QvORX50ydXDkrAzeeVUgVIzNc3d7JcDvJ49KmxI3oVPQ%2Bt8IUMJe8HGFAJDasufD%2FFwxEr2l23l40q2dlKVADnFJA5&messageId=d-B53A1D13-E%2C0%7CF%2C0%7CG%2C1
16:56:26.8962939 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - OnError(Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Tue, 15 Nov 2016 16:56:22 GMT
Set-Cookie: ARRAffinity=9fa33f4c59eaa0cb53ffc0472e2395fa67ff17a0f59613b57fb963b1519ab999;Path=/;Domain=gf-test-signalr.azurewebsites.net
Server: Microsoft-IIS/8.0
Content-Length: 326
Content-Type: text/html; charset=us-ascii
}
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass5_0.<Get>b__1(HttpResponseMessage responseMessage)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass31_0`2.<Then>b__0(Task`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3_0.<RunTask>b__0(Task`1 t))
16:56:28.9148136 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: GET http://gf-test-signalr.azurewebsites.net/signalr/reconnect?clientProtocol=1.4&transport=serverSentEvents&connectionData=[{"Name":"PingHub"}]&connectionToken=9Vs1ACQjDX%2BQmrcJ2XnoLCCJN%2FDtlJd%2BM0r5o8QvORX50ydXDkrAzeeVUgVIzNc3d7JcDvJ49KmxI3oVPQ%2Bt8IUMJe8HGFAJDasufD%2FFwxEr2l23l40q2dlKVADnFJA5&messageId=d-B53A1D13-E%2C0%7CF%2C0%7CG%2C1
16:56:29.0051243 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - OnError(Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Tue, 15 Nov 2016 16:56:24 GMT
Server: Microsoft-IIS/8.0
Content-Length: 326
Content-Type: text/html; charset=us-ascii
}
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass5_0.<Get>b__1(HttpResponseMessage responseMessage)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass31_0`2.<Then>b__0(Task`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3_0.<RunTask>b__0(Task`1 t))
16:56:31.0165736 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - SSE: GET http://gf-test-signalr.azurewebsites.net/signalr/reconnect?clientProtocol=1.4&transport=serverSentEvents&connectionData=[{"Name":"PingHub"}]&connectionToken=9Vs1ACQjDX%2BQmrcJ2XnoLCCJN%2FDtlJd%2BM0r5o8QvORX50ydXDkrAzeeVUgVIzNc3d7JcDvJ49KmxI3oVPQ%2Bt8IUMJe8HGFAJDasufD%2FFwxEr2l23l40q2dlKVADnFJA5&messageId=d-B53A1D13-E%2C0%7CF%2C0%7CG%2C1
16:56:56.7950186 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - OnError(System.TimeoutException: Couldn't reconnect within the configured timeout of 00:00:30, disconnecting.)
16:56:56.7959897 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - Disconnected
16:56:56.8103502 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - Transport.Dispose(6171c2d4-a9dd-4fa4-b710-0910af48132b)
16:56:56.8108527 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - Closed

最佳答案

16:56:56.7950186 - 6171c2d4-a9dd-4fa4-b710-0910af48132b - OnError(System.TimeoutException: Couldn't reconnect within the configured timeout of 00:00:30, disconnecting.)

据我所知,DisconnectTimeout的默认值为30秒。并且根据日志,重新连接大约需要30秒,所以请检查您是否 set/change DisconnectTimeout setting in Application_Start .

GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);

此外,如果您希望在连接丢失后不断重新连接到集线器,您可以从断开连接事件处理程序中调用 Start 方法。更详细的信息请引用“How to continuously reconnect ”。

关于azure - Azure Web App 重新启动后 SignalR 重新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40615663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com