When a client disconnects disgracefully (such as cable pull, crash, or internet drops). OnDisconnectedAsync on the server is never called. I've waited upwards of 15 minutes with a breakpoint inside the function.
I am using Microsoft.AspNetCore.SignalR (1.0.2)
.
My application is being hosted as an Azure App Service
.
This is my disconnect function:
public override async Task OnDisconnectedAsync(Exception exception)
{
try
{
if (_accountContextIDMap.TryGetValue(Context.ConnectionId, out int accountID))
{
ClientRequest_UserLoggedOut(accountID);
}
Logger.Write($"{Context.ConnectionId} Disconnected");
await base.OnDisconnectedAsync(exception);
}
catch (Exception ex)
{
Logger.Write($"{ex.Message}\n{ex.StackTrace}");
}
}
If I sit a breakpoint at the top of this function it's never called. It is called fine when I close or exit my application in a normal manner.
According to: https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events it states.
If a client application or the computer that it's running on crashes or goes to sleep (for example, when the user closes the laptop), the server is not informed about what happened. As far as the server knows, the loss of the client might be due to connectivity interruption and the client might be trying to reconnect. Therefore, in these scenarios the server waits to give the client a chance to reconnect, and OnDisconnected does not execute until the disconnect timeout period expires (about 30 seconds by default).
The statement about OnDisconnected
being called after 30 seconds by default does not seem to be ringing true for me. Any help on figuring out where I may have gone wrong in setup would be appreciated.
In my Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSignalR();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseSignalR(route => { route.MapHub<GameHub>("/gameHub", GameHubConfigureOptions); });
...
}
private void GameHubConfigureOptions(HttpConnectionDispatcherOptions options)
{
options.Transports = HttpTransportType.WebSockets;
}