Handling forced disconnects
RoccoDevs opened this issue · comments
I can't find a way to handle forced disconnects. When a socket client (java) gets shut down unexpectedly I want to handle that. I'm keeping track of some list of connections with ID's. And I need to remove connections on that list when they're closed in any way.
Currently doing it this way: but this only seems to work when sockets get closed in the proper way.
public override async Task OnConnectedAsync(ConnectionContext connection)
{
var protocol = new SixtyNineReader();
var reader = connection.CreateReader();
while (!connection.ConnectionClosed.IsCancellationRequested)
{
//code ommited
}
_logger.LogInformation($"Disconnected: {connection.ConnectionId}");
_connectionStore.Remove(connection);
}
Never mind I found a way.
var protocol = new SixtyNineReader();
var reader = connection.CreateReader();
while (!connection.ConnectionClosed.IsCancellationRequested)
{
try
{
//omitted
}
catch (ConnectionResetException)
{
//omitted
}
finally
{
reader.Advance();
}
}
_logger.LogInformation($"Disconnected: {connection.ConnectionId}");
_connectionStore.Remove(connection);
```