question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection to Azure service drops and cannot automatically recover

See original GitHub issue

Yesterday our web applications had connections to the Azure SignalR service dropped. We got several errors like this:

Connection "0a2f27dc-80e1-451e-aa4d-999d4bb950c6" to the service was dropped.

System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
   at async Task<WebSocketReceiveResult> System.Net.WebSockets.WebSocketBase+WebSocketOperation.Process(Nullable<ArraySegment<byte>> buffer, CancellationToken cancellationToken)
   at async Task<WebSocketReceiveResult> System.Net.WebSockets.WebSocketBase.ReceiveAsyncCore(ArraySegment<byte> buffer, CancellationToken cancellationToken)
   at async Task Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.StartReceiving(WebSocket socket)
   at void System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
   at void System.IO.Pipelines.Pipe.GetReadResult(ref ReadResult result)
   at ReadResult System.IO.Pipelines.Pipe.GetReadAsyncResult()
   at async Task Microsoft.Azure.SignalR.ServiceConnectionBase.ProcessIncomingAsync()

It looked like one application instance dropped all connections and the other only dropped one.

Then we got several thousand of these errors:

Error while sending message to the service.

Microsoft.Azure.SignalR.Common.ServiceConnectionNotActiveException: The connection is not active, data cannot be sent to the service.
   at async Task Microsoft.Azure.SignalR.ServiceConnectionBase.WriteAsync(ServiceMessage serviceMessage)
   at async Task Microsoft.Azure.SignalR.ServiceConnection.ProcessOutgoingMessagesAsync(ServiceConnectionContext connection)

Then several thousand of these:

Failed writing message. Aborting connection.

System.InvalidOperationException: Writing is not allowed after writer was completed.
   at void System.IO.Pipelines.ThrowHelper.ThrowInvalidOperationException_NoWritingAllowed()
   at Memory<byte> System.IO.Pipelines.Pipe.GetMemory(int sizeHint)
   at Span<byte> System.IO.Pipelines.Pipe+DefaultPipeWriter.GetSpan(int sizeHint)
   at ValueTask<FlushResult> System.IO.Pipelines.PipeWriter.WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken)
   at async Task Microsoft.AspNetCore.SignalR.HubConnectionContext.TryWritePingSlowAsync()

This went on for over an hour until the web applications were manually restarted. Then the apps were able to re-connect and things were fine.

Versions: JS client: 1.1.0 Microsoft.AspNetCore.SignalR: 1.1.0 Microsoft.Azure.SignalR: 1.0.6

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:32 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
NArnottcommented, May 17, 2019

This seems to be happening twice a week for us, forcing us to restart our service that connects to Azure SignalR.

Microsoft.Azure.SignalR.Common.ServiceConnectionNotActiveException: The connection is not active, data cannot be sent to the service.
   at Microsoft.Azure.SignalR.ServiceConnectionBase.WriteAsync(ServiceMessage serviceMessage)
   at Microsoft.Azure.SignalR.ServiceConnection.ProcessOutgoingMessagesAsync(ServiceConnectionContext connection)

We’re currently using Microsoft.Azure.SignalR version 1.0.9. This is on a Standard Tier, 1 unit Azure SignalR instance.

This is our startup code:

public void ConfigureServices(IServiceCollection services)
{
...

            var signalRBuilder = services.AddSignalR();
            if (!Env.IsDevelopment())
            {
                signalRBuilder.AddAzureSignalR(x =>
                {
                    x.ConnectionString = Configuration.GetConnectionString("AzureSignalR");

                    //Seperate out each environment into a seperate SignalR service
                    x.ApplicationName = Env.EnvironmentName;

                    if (!Env.IsProduction())
                    {
                        //We don't need the default 5 connections for test environments.
                        x.ConnectionCount = 1;
                    }
                });
            }
...
}

public void Configure(IApplicationBuilder app)
{
...
            if (Env.IsDevelopment())
            {
                app.UseSignalR(x =>
                {
                    x.MapHub<PushNotificationsHub>("/hubs/pushNotifications");
                });
            }
            else
            {
                app.UseAzureSignalR(x =>
                {
                    x.MapHub<PushNotificationsHub>("/hubs/pushNotifications");
                });
            }
...
}

1reaction
vicancycommented, Apr 1, 2019

@yosigolan Connection limits are client+server connections in total, that is 20.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Azure VM replication in Azure Site Recovery
This article describes how to troubleshoot common errors in Azure Site Recovery during replication and recovery of Azure virtual machines ...
Read more >
Troubleshoot common connection issues to Azure SQL ...
Provides steps to troubleshoot Azure SQL Database connection issues and resolve other Azure SQL Database or Azure SQL Managed Instance ...
Read more >
Troubleshooting connectivity problems between Azure VMs
Learn how to troubleshoot and resolve the connectivity problems that you might experience between Azure virtual machines (VMs).
Read more >
Troubleshoot Azure Resource Manager service connections
Select Service principal (automatic), and then select **Next. Select Subscription, and then select your subscription from the drop-down list.
Read more >
Troubleshoot connection issues - Azure Database for MySQL
Learn how to troubleshoot connection issues to Azure Database for MySQL, including transient errors requiring retries, firewall issues, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found