locked
ConnectionMaps persist after Azure App Service restart RRS feed

  • Question

  • User1176091109 posted

    We're using SignalR in Azure mostly according to the examples in the documentation:

    • We store connection information in memory using the example ConnectionMapping class. (https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/mapping-users-to-connections)
    • We support scaling out using Azure Service Bus. (https://docs.microsoft.com/en-us/aspnet/signalr/overview/performance/scaleout-with-windows-azure-service-bus)

    Everything works well until our app service restarts (which isn't under our control). After our app service restarts, we find that the old instance of the connection map - stored in the static variable of our hub - still exists and is receiving messages from the Service Bus when users connect and/or disconnect. The new instance of the connection map in the hub also exists and is simultaneously receiving messages by the Service Bus when users connect and/or disconnect.

    Through logging I've been able to determine that the old connection map is in one app domain and the new connection map is in another app domain. I expected the old connection map would be garbage collected and no longer used when the app service restarted.

    One difference between our code and the examples is that our ConnectionMapping class listens to messages on the Service bus so that all instances are kept in sync. In the constructor of our ConnectionMapping class we have:

    :
    
                    this.topicClient = TopicClient.CreateFromConnectionString(connectionString, topicName);
    
                    var subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName);
    
                    // Configure the callback options.
                    var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = TimeSpan.FromMinutes(1) };
    
                    // This is the Message handler
                    subscriptionClient.OnMessage((brokeredMessage) =>
                    {
                        try
                        {
                            string message = brokeredMessage.GetBody<string>();
                            string[] messageParts = message.Split(concatChar);
    
                            if (messageParts.Length == 3)
                            {
                                this.ProcessMessage(messageParts[0], (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(messageParts[1]), messageParts[2]);
                            }
    
                            // Remove message from subscription.
                            brokeredMessage.Complete();
                        }
                        catch (Exception ex)
                        {
                            // Indicates a problem, unlock message in subscription.
                            brokeredMessage.Abandon();
                        }
                    }, options);
    
                    // Send a synchronize message to populate from other servers
                    this.SendMessage(nameof(Synchronize), default(T), String.Empty);
    

    I'm wondering if the call to subscriptionClient.OnMessage() is causing the issue. If so, what code do I need to run to clean up this reference?

    Has anyone else seen this behavior?

    Any ideas would be appreciated.

    Thanks,

    = Luke =

    Friday, February 9, 2018 7:15 PM

All replies

  • User61956409 posted

    Hi Luke,

    the old instance of the connection map - stored in the static variable of our hub - still exists and is receiving messages from the Service Bus when users connect and/or disconnect.

    Do you mean that the old instances still process messages after web app restarts? if possible, you can open an issue to report it.

    With Regards,

    Fei Han

    Monday, February 12, 2018 5:57 AM