in src/Microsoft.Azure.SignalR.AspNet/ServerConnections/ServiceConnection.cs [295:342]
private async Task ProcessMessageAsync(ClientConnectionContext clientContext, CancellationToken cancellation)
{
var connectionId = clientContext.ConnectionId;
try
{
// Check if channel is closed.
while (await clientContext.Input.WaitToReadAsync(cancellation))
{
while (clientContext.Input.TryRead(out var serviceMessage))
{
cancellation.ThrowIfCancellationRequested();
switch (serviceMessage)
{
case OpenConnectionMessage openConnectionMessage:
await OnConnectedAsyncCore(clientContext, openConnectionMessage);
break;
case CloseConnectionMessage closeConnectionMessage:
// should not wait for application task when inside the application task
// As the messages are in a queue, close message should be after all the other messages
await PerformDisconnectCore(closeConnectionMessage.ConnectionId, false);
return;
case ConnectionDataMessage connectionDataMessage:
ProcessOutgoingMessages(clientContext, connectionDataMessage);
break;
default:
break;
}
}
}
}
catch (OperationCanceledException)
{
// Canceled
}
catch (Exception e)
{
// Internal exception is already caught and here only for channel exception.
// Notify client to disconnect.
Log.SendLoopStopped(Logger, connectionId, e);
_ = PerformDisconnectCore(connectionId, false);
_ = SafeWriteAsync(new CloseConnectionMessage(connectionId, e.Message));
}
}