Azure / azure-signalr

Azure SignalR Service SDK for .NET
https://aka.ms/signalr-service
MIT License
427 stars 101 forks source link

OperationCanceledException from Microsoft.Azure.SignalR.ServiceConnection when app restarts #1777

Open vicancy opened 1 year ago

vicancy commented 1 year ago

Describe the bug

Facing OperationCanceledException from Microsoft.Azure.SignalR.ServiceConnection specially during every deployment or webapp restart or sometimes we have seen this exception coming even when deployment or restart is not done.

And further there are 2 subtypes :

  1. Error while skipping handshake response
  2. Error while processing messages

The operation was canceled.

Exception: System.OperationCanceledException: The operation was canceled. at System.Threading.CancellationToken.ThrowOperationCanceledException() at System.IO.Pipelines.Pipe.GetReadAsyncResult() at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token) at Microsoft.Azure.SignalR.ServiceConnection.SkipHandshakeResponse(ClientConnectionContext connection, CancellationToken token)

Solution

we can silently fail the connection instead of throwing out the exception

To Reproduce

Exceptions (if any)

Further technical details

bodamgaard commented 1 week ago

Experiencing this too :-) Anyone knows how to handle this gracefully? When we deploy (rolling deployments), we'll get this exception in our log for each connection, which tends to get a bit too spammy.

vicancy commented 1 week ago

Experiencing this too :-) Anyone knows how to handle this gracefully? When we deploy (rolling deployments), we'll get this exception in our log for each connection, which tends to get a bit too spammy.

Hi @bodamgaard could you share the callstack? are you using the latest SDK? I'd like to double confirm the latest exception thrown.

bodamgaard commented 1 week ago

Experiencing this too :-) Anyone knows how to handle this gracefully? When we deploy (rolling deployments), we'll get this exception in our log for each connection, which tends to get a bit too spammy.

Hi @bodamgaard could you share the callstack? are you using the latest SDK? I'd like to double confirm the latest exception thrown.

Sure, this is the exception that I have in our log. Very limited callstack ;-) :

System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.IO.Pipelines.Pipe.GetReadAsyncResult()
   at Microsoft.Azure.SignalR.ClientConnectionContext.ProcessOutgoingMessagesAsync(IHubProtocol protocol)

Source context: Microsoft.Azure.SignalR.ServiceConnection Message template: Error while processing messages from {TransportConnectionId}.

Using this version of Microsoft.Azure.SignalR: <PackageReference Include="Microsoft.Azure.SignalR" Version="1.28.0" />

Hope that is useful :-)