SignalR - OnDisconnected is called too late

蹲街弑〆低调 提交于 2019-12-08 14:04:09

问题


I'm having a self hosted SignalR 2.2.0 server and using OWIN for the configuration.

[assembly: OwinStartup(typeof(Server.Communication.StartUp))]
namespace Server.Communication
{
    public class StartUp
    {
        public void Configuration(IAppBuilder app)
        {
            app.Map("/Communication", map =>
            {
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration { EnableDetailedErrors = true};
                map.RunSignalR(hubConfiguration);
            });
        }
    }
}

Im starting the server via

WebApp.Start($"http://{ip}:{port}");

And in my Hub I've overridden the method

public override Task OnDisconnected(bool stopCalled)

Everything works fine and the OnDisconnected method is called if I let my client crash via windows task explorer to simulate a crash. But the OnDisconnected method is called a bit late. There are at least 30 seconds till the method is called. I want to set this time to 10 seconds.

I tried setting KeepAlive and ConnectionTimeout before i call the WebApp.Start method but it did not change anything.

GlobalHost.Configuration.ConnectionTimeout = new TimeSpan(0, 0, 10);
GlobalHost.Configuration.KeepAlive = new TimeSpan(0, 0, 2);

来源:https://stackoverflow.com/questions/44389293/signalr-ondisconnected-is-called-too-late

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!